home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 February / macformat-047.iso / Shareware Plus / Developers / The Gray Council 1.2.1 / source / MacApp / GrayCouncilMA.cpp next >
Encoding:
Text File  |  1996-11-07  |  85.1 KB  |  3,262 lines  |  [TEXT/CWIE]

  1. //
  2. // The Gray Council MacApp Adapter
  3. // Copyright ©1996 by Trygve Isaacson. All Rights Reserved.
  4. //
  5. // MacApp adapter classes for The Gray Council core classes.
  6. //
  7. // Before using any of the Gray Council source code, read and
  8. // follow the licensing info in the accompanying documentation
  9. // or contact:
  10. //   <trygve@bombaydigital.com>
  11. //   <http://www.bombaydigital.com>
  12. //
  13. // Also check the web site above to make sure you have the latest version!
  14. //
  15. // The Gray Council provides a set of standard C++ classes that implement
  16. // the standard Apple Grayscale Appearance. The core classes do not
  17. // require any other code such as a particular class framework.
  18. //
  19. // This file defines a set of helper classes that derive from standard
  20. // MacApp view classes, and interface with the core Gray Council code.
  21. // There are also a couple of adorner subclasses for attaching to windows
  22. // and list boxes to get the correct background color or target border.
  23. //
  24. // Normally, to use a Gray Council MacApp class, you can simply change the
  25. // class name of the subview in your resource file or AdLib view to the
  26. // class name of the appropriate Gray Council MacApp adapter class. For
  27. // example, to use the GC pushbutton, create a normal TButton subview,
  28. // and set its class name to AGAPushButtonMA. Voila.
  29. //
  30. // A couple of the classes use the userData field of the subview to specify
  31. // additional information such as icon IDs, string resource IDs, etc.
  32. //
  33. // To statically instantiate one of these MacApp subclasses at runtime,
  34. // not via a view resource, use the class' supplied "I" method.
  35. //
  36. // Each class here that interfaces to a core AGAObject has a public
  37. // member variable called mAGAObject that points to the actual AGAObject
  38. // subclass object. Certain extended object settings (such as mixed-state
  39. // buttons, proportional and live scrolling, etc.) require you to call
  40. // the AGAObject to set it. The member variable is made public to keep
  41. // these MacApp classes as lightweight as possible; you make the call,
  42. // rather than using myriad new functions of the MacApp AGA subclasses.
  43. //
  44. // Classes defined below:
  45. //    AGAPushButtonMA -- TButton subclass for AGAPushButton
  46. //    AGACheckBoxMA -- TCheckBox subclass for AGACheckBox
  47. //    AGARadioButtonMA -- TRadio subclass for AGARadioButton
  48. //    AGAIconPushButtonMA -- AGAPushButtonMA (TButton) subclass for AGAIconPushButton
  49. //    AGAIconCheckBoxMA -- AGACheckBoxMA (TCheckBox) subclass for AGAIconCheckBox
  50. //    AGAIconRadioButtonMA -- AGARadioButtonMA (TRadio) subclass for AGAIconRadioButton
  51. //    AGAScrollBarMA -- TScrollBar subclass for AGAScrollBar
  52. //    AGAScrollerScrollBarMA -- TScrollerScrollBar subclass for AGAScrollBar
  53. //        Remember the difference between TScrollBar and TScrollerScrollBar!
  54. //    AGASliderMA -- TControl subclass for AGASlider
  55. //    AGABackgroundAdornerMA -- TAdorner subclass that you should attach to
  56. //        typical modeless windows; gives it the proper modeless gray background
  57. //    AGAModalBackgroundAdornerMA -- AGABackgroundAdornerMA (TAdorner) subclass
  58. //        that you should attach to modal windows (i.e., things you PoseModally);
  59. //        gives it the proper modal gray background; however, for dBoxProc and
  60. //        moveableDBoxProc windows, leaves window structure region white, so
  61. //        you may prefer to use AGAFlatBackgroundBehaviorMA in these cases
  62. //    AGAFlatBackgroundBehaviorMA -- TBehavior subclass that you should attach
  63. //        to modal windows (i.e., things you PoseModally); gives it the proper
  64. //        gray background, including the window structure region, but without
  65. //        raised edges
  66. //    AGAWhiteBackgroundAdornerMA -- TAdorner subclass you should attach to any
  67. //        view that needs a white background but lives in a gray background window
  68. //        (e.g., TEditText, TScroller containing grid, etc.)
  69. //    AGANotchedWhiteBackgroundAdornerMA -- AGAWhiteBackgroundAdornerMA (TAdorner)
  70. //        subclass that leaves a notch in the bottom right corner, such as the
  71. //        notch left by a pair of scroll bars
  72. //    AGABorderFrameAdornerMA -- TAdorner subclass that you can attach to any
  73. //        view that needs a "3D" sunken frame around it (e.g., the same things
  74. //        that need a white background adorner)
  75. //    AGANotchedBorderFrameAdornerMA -- AGABorderFrameAdornerMA (TAdorner) subclass
  76. //        that leaves a notch in the bottom right corner, such as the notch left by
  77. //        a pair of scroll bars
  78. //    AGAPopupMA -- TPopup subclass for AGAPopupMenu
  79. //    AGAStaticTextMA -- TStaticText subclass for AGAStaticText 
  80. //    AGALittleArrowsMA -- TControl subclass for AGALittleArrows
  81. //    AGADisclosureTriangleMA -- TControl subclass for AGADisclosureTriangle
  82. //    AGAProgressIndicatorMA -- TControl subclass for AGAProgressIndicator
  83. //    AGASeparatorMA -- TView subclass for AGASeparator
  84. //    AGATargetBorderViewMA -- TTargetBorderView subclass that draws AGA-style
  85. //        target border frame
  86. //    AGANotchedTargetBorderViewMA -- AGATargetBorderViewMA (TTargetBorderView) subclass
  87. //        that leaves a notch in the bottom right corner, such as the notch left by a
  88. //        pair of scroll bars
  89. //    AGATargetBorderFrameViewMA -- AGATargetBorderViewMA (TTargetBorderView)
  90. //        subclass that draws a "3D" sunken frame just like an AGABorderFrameAdornerMA
  91. //        in addition to the AGA-compatible TTargetBorderView.
  92. //    AGATargetBorderFrameViewMA -- AGATargetBorderFrameViewMA (TTargetBorderView)
  93. //        subclass that leaves a notch in the bottom right corner, such as the notch
  94. //        left by a pair of scroll bars
  95. //    AGAGroupBoxMA -- TCluster subclass for AGAGroupBox
  96. //    AGASecondaryGroupBoxMA -- AGAClusterMA (TCluster) subclass for AGAGroupBox
  97. //        with secondary box style set
  98. //    AGATabPanelMA -- TControl subclass for AGATabPanel set for large tabs.
  99. //    AGASmallTabPanelMA -- AGATabPanelMA (TControl) subclass for AGATabPanel
  100. //        set for small tabs.
  101. //
  102.  
  103. #include "GrayCouncilMA.h"
  104.  
  105. OSErr InitGrayCouncilMA()
  106.     {
  107.     //
  108.     // Register our dynamically instantiated view subclasses.
  109.     //
  110.  
  111.     MA_REGISTER_CLASS(AGAPushButtonMA);
  112.     MA_REGISTER_CLASS(AGACheckBoxMA);
  113.     MA_REGISTER_CLASS(AGARadioButtonMA);
  114.     MA_REGISTER_CLASS(AGAIconPushButtonMA);
  115.     MA_REGISTER_CLASS(AGAIconCheckBoxMA);
  116.     MA_REGISTER_CLASS(AGAIconRadioButtonMA);
  117.     MA_REGISTER_CLASS(AGAScrollBarMA);
  118.     MA_REGISTER_CLASS(AGAScrollerScrollBarMA);
  119.     MA_REGISTER_CLASS(AGASliderMA);
  120.     MA_REGISTER_CLASS(AGABackgroundAdornerMA);
  121.     MA_REGISTER_CLASS(AGAModalBackgroundAdornerMA);
  122.     MA_REGISTER_CLASS(AGAFlatBackgroundBehaviorMA);
  123.     MA_REGISTER_CLASS(AGAPopupMA);
  124.     MA_REGISTER_CLASS(AGAStaticTextMA);
  125.     MA_REGISTER_CLASS(AGALittleArrowsMA);
  126.     MA_REGISTER_CLASS(AGAWhiteBackgroundAdornerMA);
  127.     MA_REGISTER_CLASS(AGANotchedWhiteBackgroundAdornerMA);
  128.     MA_REGISTER_CLASS(AGABorderFrameAdornerMA);
  129.     MA_REGISTER_CLASS(AGANotchedBorderFrameAdornerMA);
  130.     MA_REGISTER_CLASS(AGADisclosureTriangleMA);
  131.     MA_REGISTER_CLASS(AGAProgressIndicatorMA);
  132.     MA_REGISTER_CLASS(AGASeparatorMA);
  133.     MA_REGISTER_CLASS(AGATargetBorderViewMA);
  134.     MA_REGISTER_CLASS(AGANotchedTargetBorderViewMA);
  135.     MA_REGISTER_CLASS(AGATargetBorderFrameViewMA);
  136.     MA_REGISTER_CLASS(AGANotchedTargetBorderFrameViewMA);
  137.     MA_REGISTER_CLASS(AGAGroupBoxMA);
  138.     MA_REGISTER_CLASS(AGASecondaryGroupBoxMA);
  139.     MA_REGISTER_CLASS(AGAGroupBoxMA);
  140.     MA_REGISTER_CLASS(AGASecondaryGroupBoxMA);
  141.     MA_REGISTER_CLASS(AGATabPanelMA);
  142.     MA_REGISTER_CLASS(AGASmallTabPanelMA);
  143.  
  144.     // Do Core Gray Council initialization.
  145.     return InitGrayCouncil();
  146.     }
  147.  
  148. static void SetAGAObjectFrame(TView* itsView, AGAObject* theAGAObject, const VRect& /*newViewFrame*/, Boolean /*redraw*/)
  149.     {
  150.     if (theAGAObject != NULL)
  151.         {
  152.         VRect    viewRect(0, 0, itsView->fSize.h, itsView->fSize.v);
  153.         CRect    qdRect;
  154.         
  155.         itsView->ViewToQDRect(viewRect, qdRect);
  156.  
  157.         theAGAObject->SetObjectBounds(qdRect, AGAObject::kDontRedraw);
  158.         }
  159.     }
  160.  
  161. //
  162. // AGAPushButtonMA ----------------------------------------------------
  163. //
  164.  
  165. #undef Inherited
  166. #define Inherited TButton
  167.  
  168. MA_DEFINE_CLASS_M1(AGAPushButtonMA, Inherited);
  169.  
  170. AGAPushButtonMA::AGAPushButtonMA()
  171.     {
  172.     mAGAObject = NULL;
  173.     }
  174.  
  175. AGAPushButtonMA::~AGAPushButtonMA()
  176.     {
  177.     // Delete AGA object if we successfully allocated it.
  178.  
  179.     if (mAGAObject != NULL)
  180.         delete mAGAObject;
  181.     }
  182.  
  183. void AGAPushButtonMA::IAGAPushButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel)
  184.     {
  185.     this->IButton(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel);
  186.  
  187.     this->CreateAGAObject();
  188.     }
  189.  
  190. void AGAPushButtonMA::DoPostCreate(TDocument* itsDocument)
  191.     {
  192.     // Create and set up the AGAObject.
  193.  
  194.     Inherited::DoPostCreate(itsDocument);
  195.     
  196.     this->CreateAGAObject();
  197.     }
  198.  
  199. void AGAPushButtonMA::CreateAGAObject()
  200.     {
  201.     // Instantiate the particular AGAObject subclass.
  202.     
  203.     (void) this->SetCMgrVisibility(false);
  204.  
  205.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  206.     CRect    bounds;
  207.     CStr255    viewTitle;
  208.     
  209.     this->ViewToQDRect(viewRect, bounds);
  210.     this->GetText(viewTitle);
  211.  
  212.     FailNIL(mAGAObject = new AGAPushButton(bounds, AGATextStyle(fTextStyle), viewTitle));
  213.  
  214.     if (fDimmed || ! fEnabled)
  215.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  216.  
  217.     //
  218.     // We implement the default button outline by checking for the
  219.     // presence of the TRRectAdorner by std ID, tossing it, and
  220.     // telling the AGA button object that it is a default button.
  221.     // Because the AGA default button outline is equivalent to a
  222.     // 3x3 pen outline, whereas a TButton with a TRRectAdorner is
  223.     // sized for a 4x4 outline, we need to inset the AGA object by
  224.     // 1x1.
  225.     //
  226.  
  227.     TAdorner*    rrectAdorner = this->FindRRectAdorner();
  228.     if (rrectAdorner != NULL)
  229.         {
  230.         this->DeleteAdorner(rrectAdorner, kDontInvalidate);
  231.         mAGAObject->SetDefault(AGAObject::kIsDefault, AGAObject::kFrameInside);
  232.         
  233.         mAGAObject->GetObjectBounds(bounds);
  234.         ::InsetRect(bounds, 1, 1);
  235.         mAGAObject->SetObjectBounds(bounds, AGAObject::kDontRedraw);
  236.         }
  237.     }
  238.  
  239. void AGAPushButtonMA::Draw(const VRect& /*area*/)
  240.     {
  241.     // Let the AGAObject draw itself.
  242.  
  243.     if (mAGAObject != NULL)
  244.         mAGAObject->DrawObject();
  245.     }
  246.  
  247. void AGAPushButtonMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  248.     {
  249.     // Let the MacApp and AGA objects update their locations.
  250.  
  251.     Inherited::SetFrame(newFrame, invalidate);
  252.     
  253.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  254.  
  255.     if ((mAGAObject != NULL) && mAGAObject->IsDefault())
  256.         {
  257.         // As noted above in AGAPushButtonMA::CreateObject, we need to
  258.         // inset the AGA object frame by 1x1 if it has a default outline.
  259.         
  260.         CRect    bounds;
  261.         
  262.         mAGAObject->GetObjectBounds(bounds);
  263.         ::InsetRect(bounds, 1, 1);
  264.         mAGAObject->SetObjectBounds(bounds, AGAObject::kDontRedraw);
  265.         }
  266.     }
  267.  
  268. void AGAPushButtonMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  269.     {
  270.     // Let the AGAObject track the mouse; if tracking succeeds
  271.     // handle our event number.
  272.  
  273.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  274.         this->HandleEvent(fEventNumber, this, NULL);
  275.     }
  276.  
  277. void AGAPushButtonMA::HiliteState(Boolean state, Boolean /*redraw*/)
  278.     {
  279.     // Let the AGAPushButton draw in the specified state.
  280.  
  281.     if ((mAGAObject != NULL) && this->Focus())
  282.         mAGAObject->DrawButton(state);
  283.     }
  284.  
  285. void AGAPushButtonMA::Hilite()
  286.     {
  287.     // Let the AGAPushButton draw in pressed state.
  288.  
  289.     if ((mAGAObject != NULL) && this->Focus())
  290.         mAGAObject->DrawButton(AGAObject::kPressed);
  291.     }
  292.  
  293. void AGAPushButtonMA::DimState(Boolean state, Boolean redraw)
  294.     {
  295.     // Set the AGAObject's enable state.
  296.  
  297.     fDimmed = state;
  298.  
  299.     if ((mAGAObject != NULL) && this->Focus())
  300.         mAGAObject->SetEnable(!state, redraw && this->IsVisible());
  301.     }
  302.  
  303. void AGAPushButtonMA::Dim()
  304.     {
  305.     // Set the AGAObject's enable state, with immediate redraw.
  306.  
  307.     if (mAGAObject != NULL)
  308.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  309.     }
  310.  
  311. void AGAPushButtonMA::SetEnable(Boolean state)
  312.     {
  313.     Inherited::SetEnable(state);
  314.  
  315.     // Set the AGAObject's enable state, without redraw.
  316.  
  317.     if (mAGAObject != NULL)
  318.         mAGAObject->SetEnable(state, AGAObject::kDontRedraw);
  319.     }
  320.  
  321. void AGAPushButtonMA::SetText(const CStr255& itsText, Boolean redraw)
  322.     {
  323.     // Change the current text in TCtlMgr and in
  324.     // the AGA object. Do NOT let control mgr draw.
  325.  
  326.     Inherited::SetText(itsText, kDontRedraw);
  327.  
  328.     if (mAGAObject != NULL)
  329.         {
  330.         Str255    textString;
  331.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  332.  
  333.         AGA_PLstrcpy(textString, itsText);
  334.         mAGAObject->SetTitle(textString, wantRedraw);
  335.         }
  336.     }
  337.  
  338. TAdorner* AGAPushButtonMA::FindRRectAdorner()
  339.     {
  340.     // Return the TRRectAdorner, if any, that is attached to
  341.     // this push button.
  342.  
  343.     TAdorner*    foundAdorner = NULL;
  344.  
  345.     if (fAdorners != NULL)
  346.         {
  347.         CAdornerIterator    iter(this);
  348.  
  349.         for (TAdorner* theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
  350.             {
  351.             if (MA_MEMBER(theAdorner, TRRectAdorner))
  352.                 foundAdorner = theAdorner;
  353.             }
  354.         }
  355.  
  356.     return foundAdorner;
  357.     }
  358.  
  359. //
  360. // AGACheckBoxMA ----------------------------------------------------
  361. //
  362.  
  363. #undef Inherited
  364. #define Inherited TCheckBox
  365.  
  366. MA_DEFINE_CLASS_M1(AGACheckBoxMA, Inherited);
  367.  
  368. AGACheckBoxMA::AGACheckBoxMA()
  369.     {
  370.     mAGAObject = NULL;
  371.     }
  372.  
  373. AGACheckBoxMA::~AGACheckBoxMA()
  374.     {
  375.     // Delete AGA object if we successfully allocated it.
  376.  
  377.     if (mAGAObject != NULL)
  378.         delete mAGAObject;
  379.     }
  380.  
  381. void AGACheckBoxMA::IAGACheckBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn)
  382.     {
  383.     this->ICheckBox(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn);
  384.  
  385.     this->CreateAGAObject();
  386.     }
  387.  
  388. void AGACheckBoxMA::DoPostCreate(TDocument* itsDocument)
  389.     {
  390.     // Create and set up the AGAObject.
  391.  
  392.     Inherited::DoPostCreate(itsDocument);
  393.     
  394.     this->CreateAGAObject();
  395.     }
  396.  
  397. void AGACheckBoxMA::CreateAGAObject()
  398.     {
  399.     // Instantiate the particular AGAObject subclass.
  400.  
  401.     (void) this->SetCMgrVisibility(false);
  402.  
  403.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  404.     CRect    bounds;
  405.     CStr255    viewTitle;
  406.     
  407.     this->ViewToQDRect(viewRect, bounds);
  408.     this->GetText(viewTitle);
  409.  
  410.     FailNIL(mAGAObject = new AGACheckBox(bounds, AGATextStyle(fTextStyle), viewTitle, AGAObject::kNoAutomaticState));
  411.  
  412.     if (this->GetLongVal() != 0)
  413.         mAGAObject->SetValue(AGACheckBox::kCheckBoxOn, AGAObject::kDontRedraw);
  414.  
  415.     if (fDimmed || ! fEnabled)
  416.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  417.     }
  418.  
  419. void AGACheckBoxMA::Draw(const VRect& /*area*/)
  420.     {
  421.     // Let the AGAObject draw itself.
  422.  
  423.     if (mAGAObject != NULL)
  424.         mAGAObject->DrawObject();
  425.     }
  426.  
  427. void AGACheckBoxMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  428.     {
  429.     // Let the MacApp and AGA objects update their locations.
  430.  
  431.     Inherited::SetFrame(newFrame, invalidate);
  432.     
  433.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  434.     }
  435.  
  436. void AGACheckBoxMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  437.     {
  438.     // Let the AGAObject track the mouse; if tracking succeeds
  439.     // handle our event number.
  440.  
  441.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  442.         this->HandleEvent(fEventNumber, this, NULL);
  443.     }
  444.  
  445. void AGACheckBoxMA::HiliteState(Boolean state, Boolean /*redraw*/)
  446.     {
  447.     // Let the AGACheckBox draw in the specified state.
  448.  
  449.     if ((mAGAObject != NULL) && this->Focus())
  450.         mAGAObject->DrawButton(state);
  451.     }
  452.  
  453. void AGACheckBoxMA::Hilite()
  454.     {
  455.     // Let the AGACheckBox draw in pressed state.
  456.  
  457.     if ((mAGAObject != NULL) && this->Focus())
  458.         mAGAObject->DrawButton(AGAObject::kPressed);
  459.     }
  460.  
  461. void AGACheckBoxMA::DimState(Boolean state, Boolean redraw)
  462.     {
  463.     // Set the AGAObject's enable state.
  464.  
  465.     fDimmed = state;
  466.  
  467.     if (mAGAObject != NULL)
  468.         {
  469.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  470.  
  471.         mAGAObject->SetEnable(!state, wantRedraw);
  472.         }
  473.     }
  474.  
  475. void AGACheckBoxMA::Dim()
  476.     {
  477.     // Set the AGAObject's enable state, with immediate redraw.
  478.  
  479.     if (mAGAObject != NULL)
  480.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  481.     }
  482.  
  483. void AGACheckBoxMA::SetEnable(Boolean state)
  484.     {
  485.     Inherited::SetEnable(state);
  486.  
  487.     // Set the AGAObject's enable state, without redraw.
  488.  
  489.     if (mAGAObject != NULL)
  490.         mAGAObject->SetEnable(state, AGAObject::kDontRedraw);
  491.     }
  492.  
  493. void AGACheckBoxMA::SetText(const CStr255& itsText, Boolean redraw)
  494.     {
  495.     // Change the current text in TCtlMgr and in
  496.     // the AGA object. Do NOT let control mgr draw.
  497.  
  498.     Inherited::SetText(itsText, kDontRedraw);
  499.  
  500.     if (mAGAObject != NULL)
  501.         {
  502.         Str255    textString;
  503.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  504.  
  505.         AGA_PLstrcpy(textString, itsText);
  506.         mAGAObject->SetTitle(textString, wantRedraw);
  507.         }
  508.     }
  509.  
  510. Boolean AGACheckBoxMA::IsOn()
  511.     {
  512.     // Return true if it's on.
  513.  
  514.     if (mAGAObject == NULL)
  515.         return Inherited::IsOn();
  516.     else
  517.         return mAGAObject->GetValue() == AGACheckBox::kCheckBoxOn;
  518.     }
  519.  
  520. void AGACheckBoxMA::SetState(Boolean state, Boolean redraw)
  521.     {
  522.     // Set the state to on or off.
  523.  
  524.     if (mAGAObject != NULL)
  525.         {
  526.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  527.  
  528.         mAGAObject->SetValue(state, wantRedraw);
  529.         }
  530.     }
  531.  
  532. void AGACheckBoxMA::Toggle(Boolean redraw)
  533.     {
  534.     // Toggle the state between on and off.
  535.  
  536.     if (mAGAObject != NULL)
  537.         {
  538.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  539.  
  540.         this->SetState(! this->IsOn(), wantRedraw);
  541.         }
  542.     }
  543.  
  544. void AGACheckBoxMA::ToggleIf(Boolean matchState, Boolean redraw)
  545.     {
  546.     // Toggle the state if it's currently in the specified state.
  547.  
  548.     if (mAGAObject != NULL)
  549.         if (this->IsOn() == matchState)
  550.             {
  551.             Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  552.  
  553.             this->SetState(! this->IsOn(), wantRedraw);
  554.             }
  555.     }
  556.  
  557. //
  558. // AGARadioButtonMA ----------------------------------------------------
  559. //
  560.  
  561. #undef Inherited
  562. #define Inherited TRadio
  563.  
  564. MA_DEFINE_CLASS_M1(AGARadioButtonMA, Inherited);
  565.  
  566. AGARadioButtonMA::AGARadioButtonMA()
  567.     {
  568.     mAGAObject = NULL;
  569.     }
  570.  
  571. AGARadioButtonMA::~AGARadioButtonMA()
  572.     {
  573.     // Delete AGA object if we successfully allocated it.
  574.  
  575.     if (mAGAObject != NULL)
  576.         delete mAGAObject;
  577.     }
  578.  
  579. void AGARadioButtonMA::IAGARadioButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn)
  580.     {
  581.     this->IRadio(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn);
  582.  
  583.     this->CreateAGAObject();
  584.     }
  585.  
  586. void AGARadioButtonMA::DoPostCreate(TDocument* itsDocument)
  587.     {
  588.     // Create and set up the AGAObject.
  589.  
  590.     Inherited::DoPostCreate(itsDocument);
  591.     
  592.     this->CreateAGAObject();
  593.     }
  594.  
  595. void AGARadioButtonMA::CreateAGAObject()
  596.     {
  597.     // Instantiate the particular AGAObject subclass.
  598.  
  599.     (void) this->SetCMgrVisibility(false);
  600.  
  601.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  602.     CRect    bounds;
  603.     CStr255    viewTitle;
  604.     
  605.     this->ViewToQDRect(viewRect, bounds);
  606.     this->GetText(viewTitle);
  607.  
  608.     FailNIL(mAGAObject = new AGARadioButton(bounds, AGATextStyle(fTextStyle), viewTitle, kNoGroupID, kNoGroupID, AGAObject::kNoAutomaticState));
  609.  
  610.     if (this->GetLongVal() != 0)
  611.         mAGAObject->SetValue(AGARadioButton::kRadioButtonOn, AGAObject::kDontRedraw);
  612.  
  613.     if (fDimmed || ! fEnabled)
  614.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  615.     }
  616.  
  617. void AGARadioButtonMA::Draw(const VRect& /*area*/)
  618.     {
  619.     // Let the AGAObject draw itself.
  620.  
  621.     if (mAGAObject != NULL)
  622.         mAGAObject->DrawObject();
  623.     }
  624.  
  625. void AGARadioButtonMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  626.     {
  627.     // Let the MacApp and AGA objects update their locations.
  628.  
  629.     Inherited::SetFrame(newFrame, invalidate);
  630.     
  631.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  632.     }
  633.  
  634. void AGARadioButtonMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  635.     {
  636.     // Let the AGAObject track the mouse; if tracking succeeds
  637.     // handle our event number.
  638.  
  639.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  640.         this->HandleEvent(fEventNumber, this, NULL);
  641.     }
  642.  
  643. void AGARadioButtonMA::HiliteState(Boolean state, Boolean /*redraw*/)
  644.     {
  645.     // Let the AGARadioButton draw in the specified state.
  646.  
  647.     if ((mAGAObject != NULL) && this->Focus() && this->IsVisible())
  648.         mAGAObject->DrawButton(state);
  649.     }
  650.  
  651. void AGARadioButtonMA::Hilite()
  652.     {
  653.     // Let the AGARadioButton draw in pressed state.
  654.  
  655.     if ((mAGAObject != NULL) && this->Focus() && this->IsVisible())
  656.         mAGAObject->DrawButton(AGAObject::kPressed);
  657.     }
  658.  
  659. void AGARadioButtonMA::DimState(Boolean state, Boolean redraw)
  660.     {
  661.     // Set the AGAObject's enable state.
  662.  
  663.     fDimmed = state;
  664.  
  665.     if (mAGAObject != NULL)
  666.         {
  667.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  668.  
  669.         mAGAObject->SetEnable(!state, wantRedraw);
  670.         }
  671.     }
  672.  
  673. void AGARadioButtonMA::Dim()
  674.     {
  675.     // Set the AGAObject's enable state, with immediate redraw.
  676.  
  677.     if (mAGAObject != NULL)
  678.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  679.     }
  680.  
  681. void AGARadioButtonMA::SetEnable(Boolean state)
  682.     {
  683.     Inherited::SetEnable(state);
  684.  
  685.     // Set the AGAObject's enable state, without redraw.
  686.  
  687.     if (mAGAObject != NULL)
  688.         mAGAObject->SetEnable(state, AGAObject::kDontRedraw);
  689.     }
  690.  
  691. void AGARadioButtonMA::SetText(const CStr255& itsText, Boolean redraw)
  692.     {
  693.     // Change the current text in TCtlMgr and in
  694.     // the AGA object. Do NOT let control mgr draw.
  695.  
  696.     Inherited::SetText(itsText, kDontRedraw);
  697.  
  698.     if (mAGAObject != NULL)
  699.         {
  700.         Str255    textString;
  701.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  702.  
  703.         AGA_PLstrcpy(textString, itsText);
  704.         mAGAObject->SetTitle(textString, wantRedraw);
  705.         }
  706.     }
  707.  
  708. Boolean AGARadioButtonMA::IsOn()
  709.     {
  710.     // Return true if it's on.
  711.  
  712.     if (mAGAObject == NULL)
  713.         return Inherited::IsOn();
  714.     else
  715.         return mAGAObject->GetValue() == AGARadioButton::kRadioButtonOn;
  716.     }
  717.  
  718. void AGARadioButtonMA::SetState(Boolean state, Boolean redraw)
  719.     {
  720.     // Set the state to on or off.
  721.  
  722.     if (mAGAObject != NULL)
  723.         {
  724.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  725.  
  726.         mAGAObject->SetValue(state, wantRedraw);
  727.         }
  728.     }
  729.  
  730. void AGARadioButtonMA::Toggle(Boolean redraw)
  731.     {
  732.     // Toggle the state between on and off.
  733.  
  734.     if (mAGAObject != NULL)
  735.         {
  736.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  737.  
  738.         this->SetState(! this->IsOn(), wantRedraw);
  739.         }
  740.     }
  741.  
  742. void AGARadioButtonMA::ToggleIf(Boolean matchState, Boolean redraw)
  743.     {
  744.     // Toggle the state if it's currently in the specified state.
  745.  
  746.     if (mAGAObject != NULL)
  747.         if (this->IsOn() == matchState)
  748.             {
  749.             Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  750.  
  751.             this->SetState(! this->IsOn(), wantRedraw);
  752.             }
  753.     }
  754.  
  755. //
  756. // AGAIconPushButtonMA ----------------------------------------------------
  757. //
  758.  
  759. #undef Inherited
  760. #define Inherited AGAPushButtonMA
  761.  
  762. MA_DEFINE_CLASS_M1(AGAIconPushButtonMA, Inherited);
  763.  
  764. void AGAIconPushButtonMA::IAGAIconPushButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel)
  765.     {
  766.     this->IAGAPushButtonMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel);
  767.     }
  768.  
  769. void AGAIconPushButtonMA::CreateAGAObject()
  770.     {
  771.     // Instantiate the particular AGAObject subclass.
  772.  
  773.     (void) this->SetCMgrVisibility(false);
  774.  
  775.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  776.     CRect    bounds;
  777.     
  778.     this->ViewToQDRect(viewRect, bounds);
  779.  
  780.     ResNumber    iconID = fUserArea;
  781.  
  782.     FailNIL(mAGAObject = new AGAIconPushButton(bounds, iconID, MIconButtonObject::kAutoFrame, MIconButtonObject::kAutoIconFamily));
  783.  
  784.     if (fDimmed || ! fEnabled)
  785.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  786.     }
  787.  
  788. //
  789. // AGAIconCheckBoxMA ----------------------------------------------------
  790. //
  791.  
  792. #undef Inherited
  793. #define Inherited AGACheckBoxMA
  794.  
  795. MA_DEFINE_CLASS_M1(AGAIconCheckBoxMA, Inherited);
  796.  
  797. void AGAIconCheckBoxMA::IAGAIconCheckBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn)
  798.     {
  799.     this->IAGAIconCheckBoxMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn);
  800.     }
  801.  
  802. void AGAIconCheckBoxMA::CreateAGAObject()
  803.     {
  804.     // Instantiate the particular AGAObject subclass.
  805.  
  806.     (void) this->SetCMgrVisibility(false);
  807.  
  808.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  809.     CRect    bounds;
  810.     
  811.     this->ViewToQDRect(viewRect, bounds);
  812.  
  813.     ResNumber    iconID = fUserArea;
  814.  
  815.     FailNIL(mAGAObject = new AGAIconCheckBox(bounds, AGAObject::kNoAutomaticState, iconID, iconID, MIconButtonObject::kAutoFrame, MIconButtonObject::kAutoIconFamily));
  816.  
  817.     if (this->GetLongVal() != 0)
  818.         mAGAObject->SetValue(AGACheckBox::kCheckBoxOn, AGAObject::kDontRedraw);
  819.  
  820.     if (fDimmed || ! fEnabled)
  821.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  822.     }
  823.  
  824. //
  825. // AGAIconRadioButtonMA ----------------------------------------------------
  826. //
  827.  
  828. #undef Inherited
  829. #define Inherited AGARadioButtonMA
  830.  
  831. MA_DEFINE_CLASS_M1(AGAIconRadioButtonMA, Inherited);
  832.  
  833. void AGAIconRadioButtonMA::IAGAIconRadioButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn)
  834.     {
  835.     this->IAGARadioButtonMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn);
  836.     }
  837.  
  838. void AGAIconRadioButtonMA::CreateAGAObject()
  839.     {
  840.     // Instantiate the particular AGAObject subclass.
  841.  
  842.     (void) this->SetCMgrVisibility(false);
  843.  
  844.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  845.     CRect    bounds;
  846.     
  847.     this->ViewToQDRect(viewRect, bounds);
  848.  
  849.     ResNumber    iconID = fUserArea;
  850.  
  851.     FailNIL(mAGAObject = new AGAIconRadioButton(bounds, kNoGroupID, kNoGroupID, AGAObject::kNoAutomaticState, iconID, iconID, MIconButtonObject::kAutoFrame, MIconButtonObject::kAutoIconFamily));
  852.  
  853.     if (this->GetLongVal() != 0)
  854.         mAGAObject->SetValue(AGARadioButton::kRadioButtonOn, AGAObject::kDontRedraw);
  855.  
  856.     if (fDimmed || ! fEnabled)
  857.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  858.     }
  859.  
  860. //
  861. // AGAScrollBarMA ----------------------------------------------------
  862. //
  863.  
  864. #undef Inherited
  865. #define Inherited TScrollBar
  866.  
  867. MA_DEFINE_CLASS_M1(AGAScrollBarMA, Inherited);
  868.  
  869. AGAScrollBarMA::AGAScrollBarMA()
  870.     {
  871.     mNotificationRoutine = NULL;
  872.     mUserData = 0;
  873.     mAGAObject = NULL;
  874.     }
  875.  
  876. AGAScrollBarMA::~AGAScrollBarMA()
  877.     {
  878.     // Delete AGA object if we successfully allocated it.
  879.  
  880.     if (mAGAObject != NULL)
  881.         delete mAGAObject;
  882.     }
  883.  
  884. void AGAScrollBarMA::IAGAScrollBarMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, VHSelect itsDirection, long itsVal, long itsMin, long itsMax)
  885.     {
  886.     this->IScrollBar(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsDirection, itsVal, itsMin, itsMax);
  887.  
  888.     this->CreateAGAObject();
  889.     }
  890.  
  891. void AGAScrollBarMA::InstallNotificationRoutine(AGANotifyMAPtr notificationRoutine, void* userData)
  892.     {
  893.     // Save the notification routine fn pointer and user data
  894.     // for notification handling.
  895.  
  896.     mNotificationRoutine = notificationRoutine;
  897.     mUserData = userData;
  898.     }
  899.  
  900. void AGAScrollBarMA::HandleNotification(SInt32 dataValue)
  901.     {
  902.     // Update the scrollbar value, call the installed notification
  903.     // function, and propagate our event number.
  904.  
  905.     this->SetLongVal(dataValue, kDontRedraw);
  906.  
  907.     if (mNotificationRoutine != NULL)
  908.         (*mNotificationRoutine)(this, dataValue, mUserData);
  909.     
  910.     this->HandleEvent(fEventNumber, this, NULL);
  911.  
  912.     (void) this->Focus();    // HandleEvent may have caused another view to draw
  913.     }
  914.  
  915. void AGAScrollBarMA::DoPostCreate(TDocument* itsDocument)
  916.     {
  917.     // Create and set up the AGAObject.
  918.  
  919.     Inherited::DoPostCreate(itsDocument);
  920.     
  921.     this->CreateAGAObject();
  922.     }
  923.  
  924. void AGAScrollBarMA::CreateAGAObject()
  925.     {
  926.     // Instantiate the particular AGAObject subclass.
  927.  
  928.     (void) this->SetCMgrVisibility(false);
  929.  
  930.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  931.     CRect    bounds;
  932.     
  933.     this->ViewToQDRect(viewRect, bounds);
  934.  
  935.     FailNIL(mAGAObject = new AGAScrollBar(bounds, this->GetLongMin(), this->GetLongMax(), this->GetLongVal()));
  936.     
  937.     mAGAObject->InstallNotificationRoutine(AGAScrollBarMA::RealAGANotifier, this);
  938.  
  939.     if (fDimmed || ! fEnabled)
  940.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  941.     }
  942.  
  943. void AGAScrollBarMA::Draw(const VRect& /*area*/)
  944.     {
  945.     // Let the AGAObject draw itself.
  946.  
  947.     if (mAGAObject != NULL)
  948.         mAGAObject->DrawObject();
  949.     }
  950.  
  951. void AGAScrollBarMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  952.     {
  953.     // Let the MacApp and AGA objects update their locations.
  954.  
  955.     Inherited::SetFrame(newFrame, invalidate);
  956.     
  957.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  958.     }
  959.  
  960. void AGAScrollBarMA::SetLongVal(VCoordinate itsVal, Boolean redraw)
  961.     {
  962.     // Catch all value changes here and synchronize the
  963.     // AGAScrollBar accordingly.
  964.  
  965.     Inherited::SetLongVal(itsVal, kDontRedraw);
  966.     
  967.     if (mAGAObject != NULL)
  968.         {
  969.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  970.  
  971.         mAGAObject->SetValue(itsVal, wantRedraw);
  972.         }
  973.     }
  974.  
  975. void AGAScrollBarMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  976.     {
  977.     // Let the AGAObject track the mouse. Don't call HandleEvent;
  978.     // it has already been handled through HandleNotification.
  979.  
  980.     (void) mAGAObject->TrackMouse(this->ViewToQDPt(theMouse));
  981.     }
  982.  
  983. void AGAScrollBarMA::HiliteState(Boolean /*state*/, Boolean /*redraw*/)
  984.     {
  985.     // Suppress Control Manager scroll bar drawing.
  986.     }
  987.  
  988. void AGAScrollBarMA::Hilite()
  989.     {
  990.     // Suppress Control Manager scroll bar drawing.
  991.     }
  992.  
  993. void AGAScrollBarMA::DimState(Boolean state, Boolean redraw)
  994.     {
  995.     // Set the AGAObject's enable state.
  996.  
  997.     fDimmed = state;
  998.  
  999.     if (mAGAObject != NULL)
  1000.         {
  1001.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  1002.  
  1003.         mAGAObject->SetEnable(!state, wantRedraw);
  1004.         }
  1005.     }
  1006.  
  1007. void AGAScrollBarMA::Dim()
  1008.     {
  1009.     // Set the AGAObject's enable state, with immediate redraw.
  1010.  
  1011.     if (mAGAObject != NULL)
  1012.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  1013.     }
  1014.  
  1015. void AGAScrollBarMA::SetEnable(Boolean state)
  1016.     {
  1017.     Inherited::SetEnable(state);
  1018.  
  1019.     // Set the AGAObject's enable state, without redraw.
  1020.  
  1021.     if (mAGAObject != NULL)
  1022.         mAGAObject->SetEnable(state, AGAObject::kDontRedraw);
  1023.     }
  1024.  
  1025. void AGAScrollBarMA::Activate(Boolean entering)
  1026.     {
  1027.     // Set the AGAScrollBar's activated state.
  1028.  
  1029.     if (mAGAObject != NULL)
  1030.         mAGAObject->Activate(entering, this->Focus() && this->IsVisible());
  1031.     }
  1032.  
  1033. void AGAScrollBarMA::SetLongMax(VCoordinate itsMax, Boolean redraw)
  1034.     {
  1035.     // Set the AGAScrollBar's limit.
  1036.     
  1037.     Inherited::SetLongMax(itsMax, kDontRedraw);
  1038.  
  1039.     if (mAGAObject != NULL)
  1040.         {
  1041.         SInt32    itsMin;
  1042.         SInt32    itsMax;
  1043.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  1044.  
  1045.         mAGAObject->GetRange(&itsMin, &itsMax);
  1046.         mAGAObject->SetRange(itsMin, this->GetLongMax(), wantRedraw);
  1047.         }
  1048.     }
  1049.  
  1050. void AGAScrollBarMA::RealAGANotifier(AGATrackingIndicator* /*theIndicator*/, SInt32 dataValue, void* userData)
  1051.     {
  1052.     // This is a static function. Cast the user data to get
  1053.     // the AGAScrollBarMA object, have it handle the notification.
  1054.  
  1055.     ((AGAScrollBarMA*) userData)->HandleNotification(dataValue);
  1056.     }
  1057.  
  1058. //
  1059. // AGAScrollerScrollBarMA ----------------------------------------------------
  1060. //
  1061.  
  1062. #undef Inherited
  1063. #define Inherited TScrollerScrollBar
  1064.  
  1065. MA_DEFINE_CLASS_M1(AGAScrollerScrollBarMA, Inherited);
  1066.  
  1067. AGAScrollerScrollBarMA::AGAScrollerScrollBarMA()
  1068.     {
  1069.     mNotificationRoutine = NULL;
  1070.     mUserData = 0;
  1071.     mAGAObject = NULL;
  1072.     }
  1073.  
  1074. AGAScrollerScrollBarMA::~AGAScrollerScrollBarMA()
  1075.     {
  1076.     // Delete AGA object if we successfully allocated it.
  1077.  
  1078.     if (mAGAObject != NULL)
  1079.         delete mAGAObject;
  1080.     }
  1081.  
  1082. void AGAScrollerScrollBarMA::IAGAScrollerScrollBarMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, VHSelect itsDirection, long itsMax, TScroller* itsScroller)
  1083.     {
  1084.     this->IScrollerScrollBar(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsDirection, itsMax, itsScroller);
  1085.  
  1086.     this->CreateAGAObject();
  1087.     }
  1088.  
  1089. void AGAScrollerScrollBarMA::InstallNotificationRoutine(AGANotifyMAPtr notificationRoutine, void* userData)
  1090.     {
  1091.     // Save the notification routine fn pointer and user data
  1092.     // for notification handling.
  1093.  
  1094.     mNotificationRoutine = notificationRoutine;
  1095.     mUserData = userData;
  1096.     }
  1097.  
  1098. void AGAScrollerScrollBarMA::HandleNotification(SInt32 dataValue)
  1099.     {
  1100.     // Scroll our scrollers and call the installed notification
  1101.     // function.
  1102.  
  1103.     CObjectIterator iter(fScrollers);
  1104.  
  1105.     for (TScroller* aScroller = (TScroller*) iter.FirstObject(); iter.More(); aScroller = (TScroller*) iter.NextObject())
  1106.         (void) aScroller->ScrollRelative(fDirection, dataValue);
  1107.  
  1108.     if (mNotificationRoutine != NULL)
  1109.         (*mNotificationRoutine)(this, dataValue, mUserData);
  1110.  
  1111.     (void) this->Focus();
  1112.     }
  1113.  
  1114. void AGAScrollerScrollBarMA::DoPostCreate(TDocument* itsDocument)
  1115.     {
  1116.     // Create and set up the AGAObject.
  1117.  
  1118.     Inherited::DoPostCreate(itsDocument);
  1119.     
  1120.     this->CreateAGAObject();
  1121.     }
  1122.  
  1123. void AGAScrollerScrollBarMA::CreateAGAObject()
  1124.     {
  1125.     // Instantiate the particular AGAObject subclass.
  1126.  
  1127.     (void) this->SetCMgrVisibility(false);
  1128.  
  1129.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  1130.     CRect    bounds;
  1131.     
  1132.     this->ViewToQDRect(viewRect, bounds);
  1133.  
  1134.     FailNIL(mAGAObject = new AGAScrollBar(bounds, this->GetLongMin(), this->GetLongMax(), this->GetLongVal()));
  1135.     
  1136.     mAGAObject->InstallNotificationRoutine(AGAScrollerScrollBarMA::RealAGANotifier, this);
  1137.  
  1138.     if (fDimmed || ! fEnabled)
  1139.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1140.  
  1141.     this->UpdateScrollAmounts();
  1142.     }
  1143.  
  1144. void AGAScrollerScrollBarMA::Draw(const VRect& /*area*/)
  1145.     {
  1146.     // Let the AGAObject draw itself.
  1147.  
  1148.     if (mAGAObject != NULL)
  1149.         mAGAObject->DrawObject();
  1150.     }
  1151.  
  1152. void AGAScrollerScrollBarMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  1153.     {
  1154.     // Let the MacApp stuff relocate and recalculate,
  1155.     // then resynchronize the AGAScrollBar to the scrollers.
  1156.  
  1157.     Inherited::SetFrame(newFrame, invalidate);
  1158.     
  1159.     this->UpdateScrollAmounts();
  1160.     
  1161.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  1162.     }
  1163.  
  1164. void AGAScrollerScrollBarMA::AttachScroller(TScroller* itsScroller)
  1165.     {
  1166.     // Synchronize the AGAScrollBar to the supplied scroller.
  1167.  
  1168.     Inherited::AttachScroller(itsScroller);
  1169.     
  1170.     this->UpdateScrollAmounts();
  1171.     }
  1172.  
  1173. void AGAScrollerScrollBarMA::SetLongVal(VCoordinate itsVal, Boolean redraw)
  1174.     {
  1175.     // Catch all value changes here and synchronize the
  1176.     // AGAScrollBar accordingly.
  1177.  
  1178.     Inherited::SetLongVal(itsVal, kDontRedraw);
  1179.     
  1180.     if (mAGAObject != NULL)
  1181.         {
  1182.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  1183.  
  1184.         mAGAObject->SetValue(itsVal, wantRedraw);
  1185.         }
  1186.     }
  1187.  
  1188. void AGAScrollerScrollBarMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  1189.     {
  1190.     // Let the AGAObject track the mouse. Don't call HandleEvent;
  1191.     // it has already been handled through HandleNotification.
  1192.  
  1193.     (void) mAGAObject->TrackMouse(this->ViewToQDPt(theMouse));
  1194.     }
  1195.  
  1196. void AGAScrollerScrollBarMA::HiliteState(Boolean /*state*/, Boolean /*redraw*/)
  1197.     {
  1198.     // Suppress Control Manager scroll bar drawing.
  1199.     }
  1200.  
  1201. void AGAScrollerScrollBarMA::Hilite()
  1202.     {
  1203.     // Suppress Control Manager scroll bar drawing.
  1204.     }
  1205.  
  1206. void AGAScrollerScrollBarMA::DimState(Boolean state, Boolean redraw)
  1207.     {
  1208.     // Set the AGAObject's enable state.
  1209.  
  1210.     fDimmed = state;
  1211.  
  1212.     if (mAGAObject != NULL)
  1213.         {
  1214.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  1215.  
  1216.         mAGAObject->SetEnable(!state, wantRedraw);
  1217.         }
  1218.     }
  1219.  
  1220. void AGAScrollerScrollBarMA::Dim()
  1221.     {
  1222.     // Set the AGAObject's enable state, with immediate redraw.
  1223.  
  1224.     if (mAGAObject != NULL)
  1225.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  1226.     }
  1227.  
  1228. void AGAScrollerScrollBarMA::SetEnable(Boolean state)
  1229.     {
  1230.     Inherited::SetEnable(state);
  1231.  
  1232.     // Set the AGAObject's enable state, without redraw.
  1233.  
  1234.     if (mAGAObject != NULL)
  1235.         mAGAObject->SetEnable(state, AGAObject::kDontRedraw);
  1236.     }
  1237.  
  1238. void AGAScrollerScrollBarMA::Activate(Boolean entering)
  1239.     {
  1240.     // Set the AGAScrollBar's activated state.
  1241.  
  1242.     if (mAGAObject != NULL)
  1243.         mAGAObject->Activate(entering, this->Focus());
  1244.     }
  1245.  
  1246. void AGAScrollerScrollBarMA::SetLongMax(VCoordinate itsMax, Boolean redraw)
  1247.     {
  1248.     // Set the AGAScrollBar's limit.
  1249.     
  1250.     Inherited::SetLongMax(itsMax, kDontRedraw);
  1251.  
  1252.     if (mAGAObject != NULL)
  1253.         {
  1254.         SInt32    itsMin;
  1255.         SInt32    itsMax;
  1256.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  1257.  
  1258.         mAGAObject->GetRange(&itsMin, &itsMax);
  1259.         mAGAObject->SetRange(itsMin, this->GetLongMax(), wantRedraw);
  1260.  
  1261.         this->UpdateScrollAmounts();
  1262.         }
  1263.     }
  1264.  
  1265. void AGAScrollerScrollBarMA::UpdateScrollAmounts()
  1266.     {
  1267.     // Synchronize the AGAScrollBar to reflect the scroller state.
  1268.  
  1269.     if ((mAGAObject != NULL) && (fScrollers->GetSize() > 0))
  1270.         {
  1271.         TScroller*    aScroller = (TScroller*) fScrollers->At(1);
  1272.         VCoordinate    maxTranslation = aScroller->fMaxTranslation[fDirection];
  1273.         VCoordinate    viewSize = aScroller->fSize[fDirection];
  1274.         VCoordinate    singleStepSize = aScroller->fScrollUnit[fDirection];
  1275.         VCoordinate    pageStepSize = Max(0, viewSize - singleStepSize);
  1276.         VCoordinate    pageSize = maxTranslation * (((float) (Max(0, viewSize - singleStepSize))) / ((float) (viewSize + maxTranslation)));
  1277.  
  1278.         (void) this->Focus();
  1279.  
  1280.         mAGAObject->SetRange(0, maxTranslation, kDontRedraw);
  1281.         mAGAObject->SetPageSize(pageSize, kRedraw);
  1282.         mAGAObject->SetStepSizes(singleStepSize, pageStepSize);
  1283.         }
  1284.     }
  1285.  
  1286. void AGAScrollerScrollBarMA::RealAGANotifier(AGATrackingIndicator* /*theIndicator*/, SInt32 dataValue, void* userData)
  1287.     {
  1288.     // This is a static function. Cast the user data to get
  1289.     // the AGAScrollerScrollBarMA object, have it handle the notification.
  1290.  
  1291.     ((AGAScrollerScrollBarMA*) userData)->HandleNotification(dataValue);
  1292.     }
  1293.  
  1294. //
  1295. // AGASliderMA ----------------------------------------------------
  1296. //
  1297.  
  1298. #undef Inherited
  1299. #define Inherited TControl
  1300.  
  1301. MA_DEFINE_CLASS_M1(AGASliderMA, Inherited);
  1302.  
  1303. AGASliderMA::AGASliderMA()
  1304.     {
  1305.     mNotificationRoutine = NULL;
  1306.     mUserData = 0;
  1307.     mAGAObject = NULL;
  1308.     }
  1309.  
  1310. AGASliderMA::~AGASliderMA()
  1311.     {
  1312.     // Delete AGA object if we successfully allocated it.
  1313.  
  1314.     if (mAGAObject != NULL)
  1315.         delete mAGAObject;
  1316.     }
  1317.  
  1318. void AGASliderMA::IAGASliderMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle)
  1319.     {
  1320.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  1321.  
  1322.     this->CreateAGAObject();
  1323.     }
  1324.  
  1325. void AGASliderMA::InstallNotificationRoutine(AGANotifyMAPtr notificationRoutine, void* userData)
  1326.     {
  1327.     // Save the notification routine fn pointer and user data
  1328.     // for notification handling.
  1329.  
  1330.     mNotificationRoutine = notificationRoutine;
  1331.     mUserData = userData;
  1332.     }
  1333.  
  1334. void AGASliderMA::HandleNotification(SInt32 dataValue)
  1335.     {
  1336.     // Update the control value, call the installed notification
  1337.     // function, and propagate our event number.
  1338.  
  1339.     //this->SetLongVal(dataValue, kDontRedraw);    TControl has no implicit value
  1340.  
  1341.     if (mNotificationRoutine != NULL)
  1342.         (*mNotificationRoutine)(this, dataValue, mUserData);
  1343.     
  1344.     this->HandleEvent(fEventNumber, this, NULL);
  1345.  
  1346.     (void) this->Focus();    // HandleEvent may have caused another view to draw
  1347.     }
  1348.  
  1349. void AGASliderMA::DoPostCreate(TDocument* itsDocument)
  1350.     {
  1351.     // Create and set up the AGAObject.
  1352.  
  1353.     Inherited::DoPostCreate(itsDocument);
  1354.     
  1355.     this->CreateAGAObject();
  1356.     }
  1357.  
  1358. void AGASliderMA::CreateAGAObject()
  1359.     {
  1360.     // Instantiate the particular AGAObject subclass.
  1361.  
  1362.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  1363.     CRect    bounds;
  1364.     
  1365.     this->ViewToQDRect(viewRect, bounds);
  1366.  
  1367.     FailNIL(mAGAObject = new AGASlider(bounds, 0, 1, 0, AGATextStyle(fTextStyle), fUserArea));
  1368.     
  1369.     mAGAObject->InstallNotificationRoutine(AGASliderMA::RealAGANotifier, this);
  1370.  
  1371.     if (fDimmed || ! fEnabled)
  1372.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1373.  
  1374.     // Slider has to erase when drawing, so make sure that
  1375.     // it doesn't assume we're on a gray background.
  1376.     
  1377.     this->Focus();
  1378.     InstallAGABackgroundColors(mAGAObject, kInstallOnlyIfCustom);
  1379.     }
  1380.  
  1381. void AGASliderMA::Draw(const VRect& /*area*/)
  1382.     {
  1383.     // Let the AGAObject draw itself.
  1384.  
  1385.     if (mAGAObject != NULL)
  1386.         mAGAObject->DrawObject();
  1387.     }
  1388.  
  1389. void AGASliderMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  1390.     {
  1391.     // Let the MacApp and AGA objects update their locations.
  1392.  
  1393.     Inherited::SetFrame(newFrame, invalidate);
  1394.     
  1395.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  1396.     }
  1397.  
  1398. void AGASliderMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  1399.     {
  1400.     // Let the AGAObject track the mouse; if tracking succeeds
  1401.     // handle our event number.
  1402.  
  1403.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  1404.         this->HandleEvent(fEventNumber, this, NULL);
  1405.     }
  1406.  
  1407. void AGASliderMA::DimState(Boolean state, Boolean redraw)
  1408.     {
  1409.     // Set the AGAObject's enable state.
  1410.  
  1411.     fDimmed = state;
  1412.  
  1413.     if (mAGAObject != NULL)
  1414.         {
  1415.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  1416.  
  1417.         mAGAObject->SetEnable(!state, wantRedraw);
  1418.         }
  1419.     }
  1420.  
  1421. void AGASliderMA::Dim()
  1422.     {
  1423.     // Set the AGAObject's enable state, with immediate redraw.
  1424.  
  1425.     if (mAGAObject != NULL)
  1426.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  1427.     }
  1428.  
  1429. void AGASliderMA::SetEnable(Boolean state)
  1430.     {
  1431.     Inherited::SetEnable(state);
  1432.  
  1433.     // Set the AGAObject's enable state, without redraw.
  1434.  
  1435.     if (mAGAObject != NULL)
  1436.         mAGAObject->SetEnable(state, AGAObject::kDontRedraw);
  1437.     }
  1438.  
  1439. void AGASliderMA::RealAGANotifier(AGATrackingIndicator* /*theIndicator*/, SInt32 dataValue, void* userData)
  1440.     {
  1441.     // This is a static function. Cast the user data to get
  1442.     // the AGASliderMA object, have it handle the notification.
  1443.  
  1444.     ((AGASliderMA*) userData)->HandleNotification(dataValue);
  1445.     }
  1446.  
  1447. //
  1448. // AGABackgroundAdornerMA ----------------------------------------------------
  1449. //
  1450.  
  1451. #undef Inherited
  1452. #define Inherited TAdorner
  1453.  
  1454. MA_DEFINE_CLASS_M1(AGABackgroundAdornerMA, Inherited);
  1455.  
  1456. AGABackgroundAdornerMA::AGABackgroundAdornerMA()
  1457.     {
  1458.     mBackgroundKind = kRaisedModelessBackground;
  1459.     }
  1460.  
  1461. void AGABackgroundAdornerMA::DoHighlightSelection(TView* itsView, const VRect& area, HLState /*fromHL*/, HLState toHL)
  1462.     {
  1463.     // Draw in the specified active/inactive state.
  1464.  
  1465.     this->DrawBackground(itsView, area, false, (toHL == hlOn));
  1466.     }
  1467.  
  1468. void AGABackgroundAdornerMA::Draw(TView* itsView, const VRect& area)
  1469.     {
  1470.     // Draw in active state.
  1471.  
  1472.     this->DrawBackground(itsView, area, true, itsView->IsActive());
  1473.     }
  1474.  
  1475. void AGABackgroundAdornerMA::ViewChangedFrame(TView* itsView, const VRect& oldFrame, const VRect& newFrame, Boolean    /*invalidate*/)
  1476.     {
  1477.     // Make sure we invalidate the edges that will need to be
  1478.     // redrawn with the background edge pixel color.
  1479.     // Note that oldFrame & newFrame are in global coordinates.
  1480.  
  1481.     VRect    rectToInvalidate;
  1482.     VPoint    sizeDelta(newFrame.GetLength(hSel) - oldFrame.GetLength(hSel),
  1483.                     newFrame.GetLength(vSel) - oldFrame.GetLength(vSel));
  1484.     
  1485.     if (sizeDelta.h != 0)
  1486.         {
  1487.         if (sizeDelta.h > 0)
  1488.             rectToInvalidate = oldFrame;
  1489.         else    // sizeDelta.h < 0
  1490.             rectToInvalidate = newFrame;
  1491.  
  1492.         rectToInvalidate.left = rectToInvalidate.right - 1;
  1493.         itsView->SuperToLocalVRect(rectToInvalidate);
  1494.         itsView->InvalidateVRect(rectToInvalidate);
  1495.         }
  1496.     
  1497.     if (sizeDelta.v != 0)
  1498.         {
  1499.         if (sizeDelta.v > 0)
  1500.             rectToInvalidate = oldFrame;
  1501.         else    // sizeDelta.v < 0
  1502.             rectToInvalidate = newFrame;
  1503.  
  1504.         rectToInvalidate.top = rectToInvalidate.bottom - 1;
  1505.         itsView->SuperToLocalVRect(rectToInvalidate);
  1506.         itsView->InvalidateVRect(rectToInvalidate);
  1507.         }
  1508.     
  1509.     if (this->HasGrowBox(itsView))
  1510.         {
  1511.         rectToInvalidate = oldFrame;
  1512.         rectToInvalidate.left = rectToInvalidate.right - 16;
  1513.         rectToInvalidate.top = rectToInvalidate.bottom - 16;
  1514.         itsView->SuperToLocalVRect(rectToInvalidate);
  1515.         itsView->InvalidateVRect(rectToInvalidate);
  1516.  
  1517.         rectToInvalidate = newFrame;
  1518.         rectToInvalidate.left = rectToInvalidate.right - 16;
  1519.         rectToInvalidate.top = rectToInvalidate.bottom - 16;
  1520.         itsView->SuperToLocalVRect(rectToInvalidate);
  1521.         itsView->InvalidateVRect(rectToInvalidate);
  1522.         }
  1523.     }
  1524.  
  1525. void AGABackgroundAdornerMA::AddedToView(TView* itsView)
  1526.     {
  1527.     // Set the current bg color of the view's port so that any of our
  1528.     // AGA adapter views that get instantiated will pick it up.
  1529.  
  1530.     if (itsView->Focus())
  1531.         ::RGBBackColor(&gAGARamp[r2]);
  1532.     }
  1533.  
  1534. void AGABackgroundAdornerMA::DrawBackground(TView* itsView, const VRect& /*area*/, Boolean fill, Boolean active)
  1535.     {
  1536.     CRect    qdArea;
  1537.     
  1538.     itsView->GetQDExtent(qdArea);
  1539.     
  1540.     AGABackgroundPaint(qdArea, fill, mBackgroundKind, active, this->HasGrowBox(itsView));
  1541.     }
  1542.  
  1543. Boolean AGABackgroundAdornerMA::HasGrowBox(TView* itsView)
  1544.     {
  1545.     if (MA_MEMBER(itsView, TWindow))
  1546.         return ((TWindow*) itsView)->fIsResizable;
  1547.     else
  1548.         return false;
  1549.     }
  1550.  
  1551.  
  1552. //
  1553. // AGAModalBackgroundAdornerMA ----------------------------------------------------
  1554. //
  1555.  
  1556. #undef Inherited
  1557. #define Inherited AGABackgroundAdornerMA
  1558.  
  1559. MA_DEFINE_CLASS_M1(AGAModalBackgroundAdornerMA, Inherited);
  1560.  
  1561. AGAModalBackgroundAdornerMA::AGAModalBackgroundAdornerMA()
  1562.     {
  1563.     mBackgroundKind = kRaisedModalBackground;
  1564.     }
  1565.  
  1566. //
  1567. // AGAFlatBackgroundBehaviorMA ----------------------------------------------------
  1568. //
  1569.  
  1570. #undef Inherited
  1571. #define Inherited TBehavior
  1572.  
  1573. MA_DEFINE_CLASS_M1(AGAFlatBackgroundBehaviorMA, Inherited);
  1574.  
  1575. AGAFlatBackgroundBehaviorMA::AGAFlatBackgroundBehaviorMA()
  1576.     {
  1577.     }
  1578.  
  1579. AGAFlatBackgroundBehaviorMA::~AGAFlatBackgroundBehaviorMA()
  1580.     {
  1581.     }
  1582.  
  1583. void AGAFlatBackgroundBehaviorMA::DoPostCreate(TDocument* itsDocument)
  1584.     {
  1585.     // Install the background color.
  1586.  
  1587.     Inherited::DoPostCreate(itsDocument);
  1588.     
  1589.     TWindow*    theWindow = ((TView*) fOwner)->GetWindow();
  1590.     
  1591.     FailOSErr(AGAInstallGrayWCTB(theWindow->fWMgrWindow));
  1592.  
  1593.     // Set the current bg color of the view's port so that any of our
  1594.     // AGA adapter views that get instantiated will pick it up.
  1595.  
  1596.     if (theWindow->Focus())
  1597.         ::RGBBackColor(&gAGARamp[r2]);
  1598.     }
  1599.  
  1600. //
  1601. // AGAWhiteBackgroundAdornerMA ----------------------------------------------------
  1602. //
  1603.  
  1604. #undef Inherited
  1605. #define Inherited TAdorner
  1606.  
  1607. MA_DEFINE_CLASS_M1(AGAWhiteBackgroundAdornerMA, Inherited);
  1608.  
  1609. void AGAWhiteBackgroundAdornerMA::Draw(TView* itsView, const VRect& /*area*/)
  1610.     {
  1611.     // Draw the background in white, inset to avoid the border
  1612.     // frame pixels.
  1613.  
  1614.     CRect    qdArea;
  1615.     
  1616.     itsView->GetQDExtent(qdArea);
  1617.     
  1618.     ::RGBForeColor(&gAGARamp[rW]);
  1619.     ::RGBBackColor(&gAGARamp[rW]);
  1620.     ::InsetRect(qdArea, 2, 2);
  1621.     ::PaintRect(qdArea);
  1622.  
  1623.     ::RGBForeColor(&gAGARamp[rB]);
  1624.     }
  1625.  
  1626. //
  1627. // AGANotchedWhiteBackgroundAdornerMA ----------------------------------------------------
  1628. //
  1629.  
  1630. #undef Inherited
  1631. #define Inherited TAdorner
  1632.  
  1633. MA_DEFINE_CLASS_M1(AGANotchedWhiteBackgroundAdornerMA, Inherited);
  1634.  
  1635. void AGANotchedWhiteBackgroundAdornerMA::Draw(TView* itsView, const VRect& /*area*/)
  1636.     {
  1637.     // Draw the background in white, inset to avoid the border
  1638.     // frame pixels.
  1639.  
  1640.     CRect    qdArea;
  1641.     
  1642.     itsView->GetQDExtent(qdArea);
  1643.     
  1644.     ::RGBForeColor(&gAGARamp[rW]);
  1645.     ::InsetRect(qdArea, 2, 2);
  1646.  
  1647.     qdArea.right -= 15;
  1648.     ::PaintRect(qdArea);
  1649.     qdArea.right += 15;
  1650.     
  1651.     qdArea.bottom -= 15;
  1652.     ::PaintRect(qdArea);
  1653.  
  1654.     ::RGBForeColor(&gAGARamp[rB]);
  1655.     }
  1656.  
  1657. //
  1658. // AGABorderFrameAdornerMA ----------------------------------------------------
  1659. //
  1660.  
  1661. #undef Inherited
  1662. #define Inherited TAdorner
  1663.  
  1664. MA_DEFINE_CLASS_M1(AGABorderFrameAdornerMA, Inherited);
  1665.  
  1666. void AGABorderFrameAdornerMA::Draw(TView* itsView, const VRect& /*area*/)
  1667.     {
  1668.     // Draw the frame with shading outside.
  1669.     
  1670.     CRect    qdArea;
  1671.     
  1672.     itsView->GetQDExtent(qdArea);
  1673.     
  1674.     AGADrawBorderFrame(qdArea, itsView->IsEnabled(), false /*isNotched*/, true /*drawFrame*/, &gAGARamp[r2]);
  1675.     
  1676.     ::RGBForeColor(&gAGARamp[rB]);
  1677.     ::RGBBackColor(&gAGARamp[rW]);
  1678.     }
  1679.  
  1680. //
  1681. // AGANotchedBorderFrameAdornerMA ----------------------------------------------------
  1682. //
  1683.  
  1684. #undef Inherited
  1685. #define Inherited TAdorner
  1686.  
  1687. MA_DEFINE_CLASS_M1(AGANotchedBorderFrameAdornerMA, Inherited);
  1688.  
  1689. void AGANotchedBorderFrameAdornerMA::Draw(TView* itsView, const VRect& /*area*/)
  1690.     {
  1691.     // Draw the frame with shading outside.
  1692.     
  1693.     CRect    qdArea;
  1694.     
  1695.     itsView->GetQDExtent(qdArea);
  1696.     
  1697.     AGADrawBorderFrame(qdArea, itsView->IsEnabled(), true /*isNotched*/, true /*drawFrame*/, &gAGARamp[r2]);
  1698.     
  1699.     ::RGBForeColor(&gAGARamp[rB]);
  1700.     ::RGBBackColor(&gAGARamp[rW]);
  1701.     }
  1702.  
  1703. //
  1704. // AGAPopupMA ----------------------------------------------------
  1705. //
  1706.  
  1707. #undef Inherited
  1708. #define Inherited TPopup
  1709.  
  1710. MA_DEFINE_CLASS_M1(AGAPopupMA, Inherited);
  1711.  
  1712. AGAPopupMA::AGAPopupMA()
  1713.     {
  1714.     mAGAObject = NULL;
  1715.     }
  1716.  
  1717. AGAPopupMA::~AGAPopupMA()
  1718.     {
  1719.     // Delete AGA object if we successfully allocated it.
  1720.  
  1721.     if (mAGAObject != NULL)
  1722.         delete mAGAObject;
  1723.     }
  1724.  
  1725. void AGAPopupMA::IAGAPopupMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, short itsMenuID, short itsCurrentItem, short itsItemOffset, short itsStrListID, short itsIndex, short itsStyle, short itsJust, Boolean useAddResMenu, ResType useAddResMenuResType, const TextStyle& itsTextStyle)
  1726.     {
  1727.     this->IPopup(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsMenuID, itsCurrentItem, itsItemOffset, itsStrListID, itsIndex, itsStyle, itsJust, useAddResMenu, useAddResMenuResType, itsTextStyle);
  1728.  
  1729.     this->CreateAGAObject();
  1730.     }
  1731.  
  1732. void AGAPopupMA::DoPostCreate(TDocument* itsDocument)
  1733.     {
  1734.     // Create and set up the AGAObject.
  1735.  
  1736.     Inherited::DoPostCreate(itsDocument);
  1737.     
  1738.     this->CreateAGAObject();
  1739.     }
  1740.  
  1741. void AGAPopupMA::CreateAGAObject()
  1742.     {
  1743.     // Instantiate the particular AGAObject subclass.
  1744.  
  1745.     (void) this->SetCMgrVisibility(false);
  1746.  
  1747.     AGAPopupMenu::WidthAdjust    widthAdjust;
  1748.     
  1749.     VRect            viewRect(0, 0, fSize.h, fSize.v);
  1750.     CRect            bounds;
  1751.     CStr255            viewTitle;
  1752.     AGATextStyle    titleStyle(fTextStyle);
  1753.     AGATextStyle    textStyle(fTextStyle);
  1754.     
  1755.     titleStyle.mFontStyle = fTitleStyle;
  1756.     textStyle.mFontStyle = normal;    // the actual popup can't have a style, even though AdLib allows it to be set
  1757.     
  1758.     this->ViewToQDRect(viewRect, bounds);
  1759.     this->GetText(viewTitle);
  1760.  
  1761.     if (fSizeDeterminer[hSel] == sizeFixed)
  1762.         widthAdjust = AGAPopupMenu::kFixedWidth;
  1763.     else
  1764.         widthAdjust = AGAPopupMenu::kSystemMDEFAdjustment;
  1765.  
  1766.     FailNIL(mAGAObject = new AGAPopupMenu(bounds, fItemOffset, viewTitle, fTitleJust, titleStyle, textStyle, widthAdjust, this->GetMenuRef(), AGAPopupMenu::kDontDispose));
  1767.  
  1768.     mAGAObject->SetCurrentItemNo((SInt16) this->GetLongVal(), AGAObject::kDontRedraw);
  1769.  
  1770.     if (fDimmed || ! fEnabled)
  1771.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1772.     }
  1773.  
  1774. void AGAPopupMA::Draw(const VRect& /*area*/)
  1775.     {
  1776.     // Let the AGAObject draw itself.
  1777.  
  1778.     if (mAGAObject != NULL)
  1779.         mAGAObject->DrawObject();
  1780.     }
  1781.  
  1782. void AGAPopupMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  1783.     {
  1784.     // Let the MacApp and AGA objects update their locations.
  1785.  
  1786.     Inherited::SetFrame(newFrame, invalidate);
  1787.     
  1788.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  1789.     }
  1790.  
  1791. void AGAPopupMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  1792.     {
  1793.     // Let the AGAObject track the mouse; if tracking succeeds
  1794.     // handle our event number.
  1795.  
  1796.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  1797.         this->HandleEvent(fEventNumber, this, NULL);
  1798.     }
  1799.  
  1800. void AGAPopupMA::DimState(Boolean state, Boolean redraw)
  1801.     {
  1802.     // Set the AGAObject's enable state.
  1803.  
  1804.     fDimmed = state;
  1805.  
  1806.     if (mAGAObject != NULL)
  1807.         {
  1808.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  1809.  
  1810.         mAGAObject->SetEnable(!state, wantRedraw);
  1811.         }
  1812.     }
  1813.  
  1814. void AGAPopupMA::Dim()
  1815.     {
  1816.     // Set the AGAObject's enable state, with immediate redraw.
  1817.  
  1818.     if (mAGAObject != NULL)
  1819.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  1820.     }
  1821.  
  1822. void AGAPopupMA::SetEnable(Boolean state)
  1823.     {
  1824.     Inherited::SetEnable(state);
  1825.  
  1826.     // Set the AGAObject's enable state, without redraw.
  1827.  
  1828.     if (mAGAObject != NULL)
  1829.         mAGAObject->SetEnable(state, AGAObject::kDontRedraw);
  1830.     }
  1831.  
  1832. void AGAPopupMA::AttachMenuRef(MenuRef itsMenuRef)
  1833.     {
  1834.     //
  1835.     // Since TPopup owns the menu, it will do the disposal.
  1836.     //
  1837.     
  1838.     Inherited::AttachMenuRef(itsMenuRef);
  1839.  
  1840.     if (mAGAObject != NULL)
  1841.         mAGAObject->SetMenuRef(itsMenuRef, AGAPopupMenu::kDontDispose);
  1842.     }
  1843.  
  1844. void AGAPopupMA::SetText(const CStr255& title, Boolean redraw)
  1845.     {
  1846.     // Install the new popup title (label).
  1847.  
  1848.     Inherited::SetText(title, redraw);
  1849.  
  1850.     if (mAGAObject != NULL)
  1851.         {
  1852.         CStr255    newTitle = title;
  1853.  
  1854.         mAGAObject->SetTitle(newTitle, redraw && this->Focus() && this->IsVisible());
  1855.         }
  1856.     }
  1857.  
  1858. void AGAPopupMA::SetLongVal(VCoordinate itsVal, Boolean redraw)
  1859.     {
  1860.     // Catch all value changes here and synchronize the
  1861.     // AGAPopupMenu accordingly.
  1862.  
  1863.     if (mAGAObject != NULL)
  1864.         mAGAObject->SetCurrentItemNo((SInt16) itsVal, redraw && this->Focus() && this->IsVisible());
  1865.     else
  1866.         Inherited::SetLongVal(itsVal, redraw);
  1867.     }
  1868.  
  1869. SInt16 AGAPopupMA::GetVal()
  1870.     {
  1871.     // Return the currently selected item number.
  1872.  
  1873.     if (mAGAObject != NULL)
  1874.         return mAGAObject->GetCurrentItemNo();
  1875.     else
  1876.         return Inherited::GetVal();
  1877.     }
  1878.  
  1879. //
  1880. // AGAStaticTextMA ----------------------------------------------------
  1881. //
  1882.  
  1883. #undef Inherited
  1884. #define Inherited TStaticText
  1885.  
  1886. MA_DEFINE_CLASS_M1(AGAStaticTextMA, Inherited);
  1887.  
  1888. AGAStaticTextMA::AGAStaticTextMA()
  1889.     {
  1890.     mAGAObject = NULL;
  1891.     }
  1892.  
  1893. AGAStaticTextMA::~AGAStaticTextMA()
  1894.     {
  1895.     // Delete AGA object if we successfully allocated it.
  1896.  
  1897.     if (mAGAObject != NULL)
  1898.         delete mAGAObject;
  1899.     }
  1900.  
  1901. void AGAStaticTextMA::IAGAStaticTextMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, ResNumber itsRsrcID, short itsIndex)
  1902.     {
  1903.     this->IStaticText(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex);
  1904.  
  1905.     this->CreateAGAObject();
  1906.     }
  1907.  
  1908. void AGAStaticTextMA::DoPostCreate(TDocument* itsDocument)
  1909.     {
  1910.     // Create and set up the AGAObject.
  1911.  
  1912.     Inherited::DoPostCreate(itsDocument);
  1913.     
  1914.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  1915.     CRect    qdRect;
  1916.     
  1917.     this->ViewToQDRect(viewRect, qdRect);
  1918.  
  1919.     this->CreateAGAObject();
  1920.  
  1921.     // A static text paints its background, so make sure that
  1922.     // it doesn't assume we're on a gray background.
  1923.  
  1924.     this->Focus();
  1925.     InstallAGABackgroundColors(mAGAObject, kInstallOnlyIfCustom);
  1926.     }
  1927.  
  1928. void AGAStaticTextMA::CreateAGAObject()
  1929.     {
  1930.     // Instantiate the particular AGAObject subclass.
  1931.  
  1932.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  1933.     CRect    bounds;
  1934.     CStr255    viewTitle;
  1935.     
  1936.     this->ViewToQDRect(viewRect, bounds);
  1937.     this->GetText(viewTitle);
  1938.  
  1939.     FailNIL(mAGAObject = new AGAStaticText(bounds, AGATextStyle(fTextStyle), fJust, viewTitle));
  1940.  
  1941.     // Note that unlike other controls, for static text, we allow
  1942.     // "disabled" text to draw normal. This is because static text
  1943.     // views typically are "disabled" but not "dimmed".
  1944.     if (fDimmed)
  1945.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1946.     }
  1947.  
  1948. void AGAStaticTextMA::DimState(Boolean state, Boolean redraw)
  1949.     {
  1950.     // Set the AGAObject's enable state.
  1951.  
  1952.     fDimmed = state;
  1953.  
  1954.     if (mAGAObject != NULL)
  1955.         {
  1956.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  1957.  
  1958.         mAGAObject->SetEnable(!state, wantRedraw);
  1959.         }
  1960.     }
  1961.  
  1962. void AGAStaticTextMA::Dim()
  1963.     {
  1964.     // Set the AGAObject's enable state, with immediate redraw.
  1965.  
  1966.     if (mAGAObject != NULL)
  1967.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  1968.     }
  1969.  
  1970. void AGAStaticTextMA::SetText(const CStr255& theText, Boolean redraw)
  1971.     {
  1972.     // Change the current text in TStaticText and in
  1973.     // the AGAStaticText. Do NOT let TStaticText redraw,
  1974.     // because it erases to white.
  1975.  
  1976.     Inherited::SetText(theText, kDontRedraw);
  1977.  
  1978.     if (mAGAObject != NULL)
  1979.         {
  1980.         Str255    textString;
  1981.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  1982.  
  1983.         AGA_PLstrcpy(textString, theText);
  1984.         mAGAObject->SetTitle(textString, wantRedraw);
  1985.         }
  1986.     }
  1987.  
  1988. void AGAStaticTextMA::Draw(const VRect& /*area*/)
  1989.     {
  1990.     // Let the AGAObject draw itself.
  1991.  
  1992.     if (mAGAObject != NULL)
  1993.         mAGAObject->DrawObject();
  1994.     }
  1995.  
  1996. void AGAStaticTextMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  1997.     {
  1998.     // Let the MacApp and AGA objects update their locations.
  1999.  
  2000.     Inherited::SetFrame(newFrame, invalidate);
  2001.     
  2002.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  2003.     }
  2004.  
  2005. //
  2006. // AGALittleArrowsMA ----------------------------------------------------
  2007. //
  2008.  
  2009. #undef Inherited
  2010. #define Inherited TControl
  2011.  
  2012. MA_DEFINE_CLASS_M1(AGALittleArrowsMA, Inherited);
  2013.  
  2014. AGALittleArrowsMA::AGALittleArrowsMA()
  2015.     {
  2016.     mNotificationRoutine = NULL;
  2017.     mUserData = 0;
  2018.     mAGAObject = NULL;
  2019.     mLinkedNumberText = NULL;
  2020.     }
  2021.  
  2022. AGALittleArrowsMA::~AGALittleArrowsMA()
  2023.     {
  2024.     // Delete AGA object if we successfully allocated it.
  2025.  
  2026.     if (mAGAObject != NULL)
  2027.         delete mAGAObject;
  2028.     }
  2029.  
  2030. void AGALittleArrowsMA::IAGALittleArrowsMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle)
  2031.     {
  2032.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  2033.  
  2034.     this->CreateAGAObject();
  2035.     }
  2036.  
  2037. void AGALittleArrowsMA::InstallNotificationRoutine(AGANotifyMAPtr notificationRoutine, void* userData)
  2038.     {
  2039.     // Save the notification routine fn pointer and user data
  2040.     // for notification handling.
  2041.  
  2042.     mNotificationRoutine = notificationRoutine;
  2043.     mUserData = userData;
  2044.     }
  2045.  
  2046. void AGALittleArrowsMA::HandleNotification(SInt32 deltaValue)
  2047.     {
  2048.     // Update the linked TNumberText, if any, call the
  2049.     // installed notification function, and propagate our
  2050.     // event number.
  2051.  
  2052.     if (mLinkedNumberText != NULL)
  2053.         mLinkedNumberText->SetValue(mLinkedNumberText->GetValue() + deltaValue, kRedraw);
  2054.  
  2055.     if (mNotificationRoutine != NULL)
  2056.         (*mNotificationRoutine)(this, deltaValue, mUserData);
  2057.     
  2058.     this->HandleEvent(fEventNumber, this, NULL);
  2059.  
  2060.     (void) this->Focus();
  2061.     }
  2062.  
  2063. void AGALittleArrowsMA::DoPostCreate(TDocument* itsDocument)
  2064.     {
  2065.     // Create and set up the AGAObject.
  2066.  
  2067.     Inherited::DoPostCreate(itsDocument);
  2068.     
  2069.     this->CreateAGAObject();
  2070.     }
  2071.  
  2072. void AGALittleArrowsMA::CreateAGAObject()
  2073.     {
  2074.     // Instantiate the particular AGAObject subclass.
  2075.  
  2076.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  2077.     CRect    bounds;
  2078.     
  2079.     this->ViewToQDRect(viewRect, bounds);
  2080.  
  2081.     FailNIL(mAGAObject = new AGALittleArrows(bounds));
  2082.     
  2083.     mAGAObject->InstallNotificationRoutine(AGALittleArrowsMA::RealAGANotifier, this);
  2084.  
  2085.     if (fDimmed || ! fEnabled)
  2086.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  2087.  
  2088.     if (fUserArea != 0)
  2089.         {
  2090.         mLinkedNumberText = (TNumberText*) this->GetWindow()->FindSubView(fUserArea);
  2091.         if (mLinkedNumberText != NULL)
  2092.             if (! MA_MEMBER(mLinkedNumberText, TNumberText))
  2093.                 mLinkedNumberText = NULL;
  2094.         }
  2095.     }
  2096.  
  2097. void AGALittleArrowsMA::Draw(const VRect& /*area*/)
  2098.     {
  2099.     // Let the AGAObject draw itself.
  2100.  
  2101.     if (mAGAObject != NULL)
  2102.         mAGAObject->DrawObject();
  2103.     }
  2104.  
  2105. void AGALittleArrowsMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  2106.     {
  2107.     // Let the MacApp and AGA objects update their locations.
  2108.  
  2109.     Inherited::SetFrame(newFrame, invalidate);
  2110.     
  2111.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  2112.     }
  2113.  
  2114. void AGALittleArrowsMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  2115.     {
  2116.     // Let the AGAObject track the mouse; if tracking succeeds
  2117.     // handle our event number.
  2118.  
  2119.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  2120.         this->HandleEvent(fEventNumber, this, NULL);
  2121.     }
  2122.  
  2123. void AGALittleArrowsMA::DimState(Boolean state, Boolean redraw)
  2124.     {
  2125.     // Set the AGAObject's enable state.
  2126.  
  2127.     fDimmed = state;
  2128.  
  2129.     if (mAGAObject != NULL)
  2130.         {
  2131.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  2132.  
  2133.         mAGAObject->SetEnable(!state, wantRedraw);
  2134.         }
  2135.     }
  2136.  
  2137. void AGALittleArrowsMA::Dim()
  2138.     {
  2139.     // Set the AGAObject's enable state, with immediate redraw.
  2140.  
  2141.     if (mAGAObject != NULL)
  2142.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  2143.     }
  2144.  
  2145. void AGALittleArrowsMA::SetEnable(Boolean state)
  2146.     {
  2147.     Inherited::SetEnable(state);
  2148.  
  2149.     // Set the AGAObject's enable state, without redraw.
  2150.  
  2151.     if (mAGAObject != NULL)
  2152.         mAGAObject->SetEnable(state, AGAObject::kDontRedraw);
  2153.     }
  2154.  
  2155. void AGALittleArrowsMA::RealAGANotifier(AGALittleArrows* /*theAGAObject*/, SInt32 deltaValue, void* userData)
  2156.     {
  2157.     // This is a static function. Cast the user data to get
  2158.     // the AGAScrollerScrollBarMA object, have it handle the notification.
  2159.  
  2160.     ((AGALittleArrowsMA*) userData)->HandleNotification(deltaValue);
  2161.     }
  2162.  
  2163. //
  2164. // AGADisclosureTriangleMA ----------------------------------------------------
  2165. //
  2166.  
  2167. #undef Inherited
  2168. #define Inherited TControl
  2169.  
  2170. MA_DEFINE_CLASS_M1(AGADisclosureTriangleMA, Inherited);
  2171.  
  2172. AGADisclosureTriangleMA::AGADisclosureTriangleMA()
  2173.     {
  2174.     mAGAObject = NULL;
  2175.     }
  2176.  
  2177. AGADisclosureTriangleMA::~AGADisclosureTriangleMA()
  2178.     {
  2179.     // Delete AGA object if we successfully allocated it.
  2180.  
  2181.     if (mAGAObject != NULL)
  2182.         delete mAGAObject;
  2183.     }
  2184.  
  2185. void AGADisclosureTriangleMA::IAGADisclosureTriangleMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle)
  2186.     {
  2187.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  2188.  
  2189.     this->CreateAGAObject();
  2190.     }
  2191.  
  2192. void AGADisclosureTriangleMA::DoPostCreate(TDocument* itsDocument)
  2193.     {
  2194.     // Create and set up the AGAObject.
  2195.  
  2196.     Inherited::DoPostCreate(itsDocument);
  2197.     
  2198.     this->CreateAGAObject();
  2199.     }
  2200.  
  2201. void AGADisclosureTriangleMA::CreateAGAObject()
  2202.     {
  2203.     // Instantiate the particular AGAObject subclass.
  2204.  
  2205.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  2206.     CRect    bounds;
  2207.     
  2208.     this->ViewToQDRect(viewRect, bounds);
  2209.  
  2210.     FailNIL(mAGAObject = new AGADisclosureTriangle(bounds, AGAObject::kAutomaticState));
  2211.  
  2212.     if (fDimmed || ! fEnabled)
  2213.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  2214.  
  2215.     // Disclosure triangle has to erase when animating, so make sure that
  2216.     // it doesn't assume we're on a gray background.
  2217.  
  2218.     this->Focus();
  2219.     InstallAGABackgroundColors(mAGAObject, kInstallOnlyIfCustom);
  2220.     }
  2221.  
  2222. void AGADisclosureTriangleMA::Draw(const VRect& /*area*/)
  2223.     {
  2224.     // Let the AGAObject draw itself.
  2225.  
  2226.     if (mAGAObject != NULL)
  2227.         mAGAObject->DrawObject();
  2228.     }
  2229.  
  2230. void AGADisclosureTriangleMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  2231.     {
  2232.     // Let the MacApp and AGA objects update their locations.
  2233.  
  2234.     Inherited::SetFrame(newFrame, invalidate);
  2235.     
  2236.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  2237.     }
  2238.  
  2239. void AGADisclosureTriangleMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  2240.     {
  2241.     // Let the AGAObject track the mouse; if tracking succeeds
  2242.     // handle our event number.
  2243.  
  2244.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  2245.         this->HandleEvent(fEventNumber, this, NULL);
  2246.     }
  2247.  
  2248. void AGADisclosureTriangleMA::DimState(Boolean state, Boolean redraw)
  2249.     {
  2250.     // Set the AGAObject's enable state.
  2251.  
  2252.     fDimmed = state;
  2253.  
  2254.     if (mAGAObject != NULL)
  2255.         {
  2256.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  2257.  
  2258.         mAGAObject->SetEnable(!state, wantRedraw);
  2259.         }
  2260.     }
  2261.  
  2262. void AGADisclosureTriangleMA::Dim()
  2263.     {
  2264.     // Set the AGAObject's enable state, with immediate redraw.
  2265.  
  2266.     if (mAGAObject != NULL)
  2267.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  2268.     }
  2269.  
  2270. void AGADisclosureTriangleMA::SetEnable(Boolean state)
  2271.     {
  2272.     Inherited::SetEnable(state);
  2273.  
  2274.     // Set the AGAObject's enable state, without redraw.
  2275.  
  2276.     if (mAGAObject != NULL)
  2277.         mAGAObject->SetEnable(state, AGAObject::kDontRedraw);
  2278.     }
  2279.  
  2280. //
  2281. // AGAProgressIndicatorMA ----------------------------------------------------
  2282. //
  2283.  
  2284. #undef Inherited
  2285. #define Inherited TControl
  2286.  
  2287. MA_DEFINE_CLASS_M1(AGAProgressIndicatorMA, Inherited);
  2288.  
  2289. AGAProgressIndicatorMA::AGAProgressIndicatorMA()
  2290.     {
  2291.     mAGAObject = NULL;
  2292.     }
  2293.  
  2294. AGAProgressIndicatorMA::~AGAProgressIndicatorMA()
  2295.     {
  2296.     // Delete AGA object if we successfully allocated it.
  2297.  
  2298.     this->StopAutoAnimate();
  2299.  
  2300.     if (mAGAObject != NULL)
  2301.         delete mAGAObject;
  2302.     }
  2303.  
  2304. void AGAProgressIndicatorMA::IAGAProgressIndicatorMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle)
  2305.     {
  2306.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  2307.  
  2308.     this->CreateAGAObject();
  2309.     }
  2310.  
  2311. void AGAProgressIndicatorMA::DoPostCreate(TDocument* itsDocument)
  2312.     {
  2313.     // Create and set up the AGAObject.
  2314.  
  2315.     Inherited::DoPostCreate(itsDocument);
  2316.     
  2317.     this->CreateAGAObject();
  2318.     }
  2319.  
  2320. void AGAProgressIndicatorMA::CreateAGAObject()
  2321.     {
  2322.     // Instantiate the particular AGAObject subclass.
  2323.  
  2324.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  2325.     CRect    bounds;
  2326.     
  2327.     this->ViewToQDRect(viewRect, bounds);
  2328.  
  2329.     FailNIL(mAGAObject = new AGAProgressIndicator(bounds, 0, 100));
  2330.  
  2331.     if (fDimmed || ! fEnabled)
  2332.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  2333.  
  2334.     if (fUserArea != 0)
  2335.         this->StartAutoAnimate();
  2336.     }
  2337.  
  2338. void AGAProgressIndicatorMA::Draw(const VRect& /*area*/)
  2339.     {
  2340.     // Let the AGAObject draw itself.
  2341.  
  2342.     if (mAGAObject != NULL)
  2343.         mAGAObject->DrawObject();
  2344.     }
  2345.  
  2346. void AGAProgressIndicatorMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  2347.     {
  2348.     // Let the MacApp and AGA objects update their locations.
  2349.  
  2350.     Inherited::SetFrame(newFrame, invalidate);
  2351.     
  2352.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  2353.     }
  2354.  
  2355. Boolean AGAProgressIndicatorMA::DoIdle(IdlePhase phase)
  2356.     {
  2357.     // Let the AGAObject do one animation step.
  2358.  
  2359.     if ((phase == idleContinue) && (mAGAObject != NULL) && this->Focus())
  2360.         mAGAObject->QuantizedAnimate();
  2361.  
  2362.     return false;    // did not free self
  2363.     }
  2364.  
  2365. void AGAProgressIndicatorMA::StartAutoAnimate()
  2366.     {
  2367.     // Place ourself on the cohandler chain so we'll get idle time.
  2368.     
  2369.     fNextHandler = NULL;    // if we still point our superview, the two chains will be confused
  2370.     this->SetIdleFreq(0);    // idle often
  2371.     this->SetEnable(true);    // we won't get idle time if we're disabled!
  2372.  
  2373.     gApplication->InstallCohandler(this, true);
  2374.     }
  2375.  
  2376. void AGAProgressIndicatorMA::StopAutoAnimate()
  2377.     {
  2378.     // Remove ourself on the cohandler chain so we don't get idle time.
  2379.     
  2380.     gApplication->InstallCohandler(this, false);
  2381.     }
  2382.  
  2383. //
  2384. // AGASeparatorMA ----------------------------------------------------
  2385. //
  2386.  
  2387. #undef Inherited
  2388. #define Inherited TView
  2389.  
  2390. MA_DEFINE_CLASS_M1(AGASeparatorMA, Inherited);
  2391.  
  2392. AGASeparatorMA::AGASeparatorMA()
  2393.     {
  2394.     mAGAObject = NULL;
  2395.     }
  2396.  
  2397. AGASeparatorMA::~AGASeparatorMA()
  2398.     {
  2399.     // Delete AGA object if we successfully allocated it.
  2400.  
  2401.     if (mAGAObject != NULL)
  2402.         delete mAGAObject;
  2403.     }
  2404.  
  2405. void AGASeparatorMA::IAGASeparatorMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet)
  2406.     {
  2407.     this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  2408.  
  2409.     this->CreateAGAObject();
  2410.     }
  2411.  
  2412. void AGASeparatorMA::DoPostCreate(TDocument* itsDocument)
  2413.     {
  2414.     // Create and set up the AGAObject.
  2415.  
  2416.     Inherited::DoPostCreate(itsDocument);
  2417.     
  2418.     this->CreateAGAObject();
  2419.     }
  2420.  
  2421. void AGASeparatorMA::CreateAGAObject()
  2422.     {
  2423.     // Instantiate the particular AGAObject subclass.
  2424.  
  2425.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  2426.     CRect    bounds;
  2427.     
  2428.     this->ViewToQDRect(viewRect, bounds);
  2429.  
  2430.     FailNIL(mAGAObject = new AGASeparator(bounds));
  2431.     }
  2432.  
  2433. void AGASeparatorMA::Draw(const VRect& /*area*/)
  2434.     {
  2435.     // Let the AGAObject draw itself.
  2436.  
  2437.     if (mAGAObject != NULL)
  2438.         mAGAObject->DrawObject();
  2439.     }
  2440.  
  2441. void AGASeparatorMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  2442.     {
  2443.     // Let the MacApp and AGA objects update their locations.
  2444.  
  2445.     Inherited::SetFrame(newFrame, invalidate);
  2446.     
  2447.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  2448.     }
  2449.  
  2450. //
  2451. // AGATargetBorderViewMA ----------------------------------------------------
  2452. //
  2453.  
  2454. #undef Inherited
  2455. #define Inherited TTargetBorderView
  2456.  
  2457. MA_DEFINE_CLASS_M1(AGATargetBorderViewMA, Inherited);
  2458.  
  2459. void AGATargetBorderViewMA::IAGATargetBorderViewMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, IDType itsTargetView)
  2460.     {
  2461.     this->ITargetBorderView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTargetView);
  2462.     }
  2463.  
  2464. void AGATargetBorderViewMA::DoPostCreate(TDocument* itsDocument)
  2465.     {
  2466.     // Save the background colors we will need to erase.
  2467.  
  2468.     Inherited::DoPostCreate(itsDocument);
  2469.     
  2470.     this->Focus();
  2471.     if (! DetermineAGABackgroundColors(&mEnabledBackgroundColor, &mDisabledBackgroundColor, kInstallOnlyIfCustom))
  2472.         {
  2473.         mEnabledBackgroundColor = gAGARamp[r2];
  2474.         mDisabledBackgroundColor = gAGARamp[r2];
  2475.         }
  2476.     }
  2477.  
  2478. void AGATargetBorderViewMA::Draw(const VRect& /*area*/)
  2479.     {
  2480.     // Set the color, always draw. TTargetBorderView leaves
  2481.     // background unerased in 1-bit.
  2482.  
  2483.     AGADrawingEnvironment    env;
  2484.  
  2485.     GDIterator    iter;
  2486.     Boolean        deep;
  2487.     Boolean        isTarget = this->ContainsTarget(gApplication->GetTarget());
  2488.     Boolean        enabled = this->IsEnabled();
  2489.  
  2490.     CTemporaryRegion borderRegion;
  2491.     
  2492.     while (iter.More(deep))
  2493.         {
  2494.         if (deep)
  2495.             {
  2496.             if (isTarget && enabled)
  2497.                 ::RGBForeColor(&gAGARamp[r8]);
  2498.             else if (enabled)
  2499.                 ::RGBForeColor(&mEnabledBackgroundColor);
  2500.             else
  2501.                 ::RGBForeColor(&mDisabledBackgroundColor);
  2502.             }
  2503.         else
  2504.             {
  2505.             if (isTarget && enabled)
  2506.                 ::RGBForeColor(&gAGARamp[rB]);
  2507.             else
  2508.                 ::RGBForeColor(&gAGARamp[rW]);
  2509.             }
  2510.  
  2511.         this->ComputeBorderRegion(borderRegion);
  2512.         PaintRgn(borderRegion);
  2513.         }
  2514.     }
  2515.  
  2516. void AGATargetBorderViewMA::ComputeBorderRegion(RgnHandle borderRegion)
  2517.     {
  2518.     // Return the border region to be painted or invalidated.
  2519.  
  2520.     CRect    qdArea;
  2521.  
  2522.     this->GetQDExtent(qdArea);
  2523.  
  2524.     AGAComputeTargetBorderRegion(borderRegion, qdArea, false /*isNotched*/);
  2525.     }
  2526.  
  2527. //
  2528. // AGANotchedTargetBorderViewMA ----------------------------------------------------
  2529. //
  2530.  
  2531. #undef Inherited
  2532. #define Inherited AGATargetBorderViewMA
  2533.  
  2534. MA_DEFINE_CLASS_M1(AGANotchedTargetBorderViewMA, Inherited);
  2535.  
  2536. void AGANotchedTargetBorderViewMA::IAGANotchedTargetBorderViewMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, IDType itsTargetView)
  2537.     {
  2538.     this->IAGATargetBorderViewMA(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTargetView);
  2539.     }
  2540.  
  2541. void AGANotchedTargetBorderViewMA::ComputeBorderRegion(RgnHandle borderRegion)
  2542.     {
  2543.     // Return the border region to be painted or invalidated.
  2544.  
  2545.     CRect    qdArea;
  2546.  
  2547.     this->GetQDExtent(qdArea);
  2548.  
  2549.     AGAComputeTargetBorderRegion(borderRegion, qdArea, true /*isNotched*/);
  2550.     }
  2551.  
  2552. //
  2553. // AGATargetBorderFrameViewMA ----------------------------------------------------
  2554. //
  2555.  
  2556. #undef Inherited
  2557. #define Inherited AGATargetBorderViewMA
  2558.  
  2559. MA_DEFINE_CLASS_M1(AGATargetBorderFrameViewMA, Inherited);
  2560.  
  2561. void AGATargetBorderFrameViewMA::IAGATargetBorderFrameViewMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, IDType itsTargetView)
  2562.     {
  2563.     this->IAGATargetBorderViewMA(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTargetView);
  2564.     }
  2565.  
  2566. void AGATargetBorderFrameViewMA::Draw(const VRect& area)
  2567.     {
  2568.     // Let the AGATargetBorderViewMA draw the target border,
  2569.     // then draw the "3D" sunken frame portion..
  2570.  
  2571.     Inherited::Draw(area);
  2572.     
  2573.     CRect    qdArea;
  2574.  
  2575.     this->GetQDExtent(qdArea);
  2576.     
  2577.     ::InsetRect(qdArea, 3, 3);
  2578.  
  2579.     AGADrawBorderFrame(qdArea, this->IsEnabled(), false /*isNotched*/, true /*drawFrame*/, &gAGARamp[r2]);
  2580.  
  2581.     ::RGBForeColor(&gAGARamp[rB]);
  2582.     ::RGBBackColor(&gAGARamp[rW]);
  2583.     }
  2584.  
  2585. void AGATargetBorderFrameViewMA::Dim()
  2586.     {
  2587.     // Suppress patBic painting over our frame.
  2588.     }
  2589.  
  2590. void AGATargetBorderFrameViewMA::SetEnable(Boolean state)
  2591.     {
  2592.     // Redraw now; unlike TControl, TView does not automatically
  2593.     // redraw when you disable/dim it.
  2594.     
  2595.     Inherited::SetEnable(state);
  2596.  
  2597.     if (this->Focus() && this->IsVisible())
  2598.         {
  2599.         VRect    extent;
  2600.         
  2601.         this->GetExtent(extent);
  2602.         this->Draw(extent);
  2603.         }
  2604.     }
  2605.  
  2606. //
  2607. // AGANotchedTargetBorderFrameViewMA ----------------------------------------------------
  2608. //
  2609.  
  2610. #undef Inherited
  2611. #define Inherited AGATargetBorderViewMA
  2612.  
  2613. MA_DEFINE_CLASS_M1(AGANotchedTargetBorderFrameViewMA, Inherited);
  2614.  
  2615. void AGANotchedTargetBorderFrameViewMA::IAGANotchedTargetBorderFrameViewMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, IDType itsTargetView)
  2616.     {
  2617.     this->IAGATargetBorderViewMA(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTargetView);
  2618.     }
  2619.  
  2620. void AGANotchedTargetBorderFrameViewMA::Draw(const VRect& area)
  2621.     {
  2622.     // Let the AGATargetBorderViewMA draw the target border,
  2623.     // then draw the "3D" sunken frame portion..
  2624.  
  2625.     Inherited::Draw(area);
  2626.     
  2627.     CRect    qdArea;
  2628.  
  2629.     this->GetQDExtent(qdArea);
  2630.     
  2631.     ::InsetRect(qdArea, 3, 3);
  2632.  
  2633.     AGADrawBorderFrame(qdArea, this->IsEnabled(), true /*isNotched*/, true /*drawFrame*/, &gAGARamp[r2]);
  2634.  
  2635.     ::RGBForeColor(&gAGARamp[rB]);
  2636.     ::RGBBackColor(&gAGARamp[rW]);
  2637.     }
  2638.  
  2639. void AGANotchedTargetBorderFrameViewMA::Dim()
  2640.     {
  2641.     // Suppress patBic painting over our frame.
  2642.     }
  2643.  
  2644. void AGANotchedTargetBorderFrameViewMA::ComputeBorderRegion(RgnHandle borderRegion)
  2645.     {
  2646.     // Return the border region to be painted or invalidated.
  2647.  
  2648.     CRect    qdArea;
  2649.  
  2650.     this->GetQDExtent(qdArea);
  2651.  
  2652.     AGAComputeTargetBorderRegion(borderRegion, qdArea, true /*isNotched*/);
  2653.     }
  2654.  
  2655. //
  2656. // AGAGroupBoxMA ----------------------------------------------------
  2657. //
  2658.  
  2659. #undef Inherited
  2660. #define Inherited TCluster
  2661.  
  2662. MA_DEFINE_CLASS_M1(AGAGroupBoxMA, Inherited);
  2663.  
  2664. AGAGroupBoxMA::AGAGroupBoxMA()
  2665.     {
  2666.     mAGAObject = NULL;
  2667.     mIsPrimaryType = true;
  2668.     }
  2669.  
  2670. AGAGroupBoxMA::~AGAGroupBoxMA()
  2671.     {
  2672.     // Delete AGA object if we successfully allocated it.
  2673.  
  2674.     if (mAGAObject != NULL)
  2675.         delete mAGAObject;
  2676.     }
  2677.  
  2678. void AGAGroupBoxMA::IAGAGroupBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, ResNumber itsRsrcID, short itsIndex)
  2679.     {
  2680.     this->ICluster(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex);
  2681.  
  2682.     this->CreateAGAObject();
  2683.     }
  2684.  
  2685. void AGAGroupBoxMA::DoPostCreate(TDocument* itsDocument)
  2686.     {
  2687.     // Create and set up the AGAObject.
  2688.  
  2689.     Inherited::DoPostCreate(itsDocument);
  2690.     
  2691.     this->CreateAGAObject();
  2692.     }
  2693.  
  2694. void AGAGroupBoxMA::CreateAGAObject()
  2695.     {
  2696.     // Instantiate the particular AGAObject subclass.
  2697.  
  2698.     CStr255    label;
  2699.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  2700.     CRect    bounds;
  2701.     
  2702.     this->ViewToQDRect(viewRect, bounds);
  2703.     this->GetLabel(label);
  2704.  
  2705.     FailNIL(mAGAObject = new AGAGroupBox(bounds, AGATextStyle(fTextStyle), mIsPrimaryType, label));
  2706.  
  2707.     if ((fUserArea != 0) && (fSuperView != NULL))
  2708.         {
  2709.         TView*    gapView = fSuperView->FindSubView(fUserArea);
  2710.  
  2711.         if (gapView != NULL)
  2712.             {
  2713.             CRect    gapExtent;
  2714.  
  2715.             gapView->GetQDExtent(gapExtent);
  2716.             mAGAObject->SetTitleGap(5 + gapExtent.GetLength(hSel));
  2717.             }
  2718.         }
  2719.  
  2720.     // Note that unlike other controls, for group boxes, we allow
  2721.     // "disabled" text to draw normal. This is because group box
  2722.     // views typically are "disabled" but not "dimmed".
  2723.     if (fDimmed)
  2724.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  2725.     }
  2726.  
  2727. void AGAGroupBoxMA::Draw(const VRect& /*area*/)
  2728.     {
  2729.     // Let the AGAObject draw itself.
  2730.  
  2731.     if (mAGAObject != NULL)
  2732.         mAGAObject->DrawObject();
  2733.     }
  2734.  
  2735. void AGAGroupBoxMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  2736.     {
  2737.     // Let the MacApp and AGA objects update their locations.
  2738.  
  2739.     Inherited::SetFrame(newFrame, invalidate);
  2740.     
  2741.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  2742.     }
  2743.  
  2744. void AGAGroupBoxMA::DoMouseCommand(VPoint& /*theMouse*/, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  2745.     {
  2746.     // Group box drawing is based on enable state, but we don't
  2747.     // want clicking on the group box itself to cause highlighting.
  2748.     }
  2749.  
  2750. void AGAGroupBoxMA::DimState(Boolean state, Boolean redraw)
  2751.     {
  2752.     // Set the AGAObject's enable state.
  2753.  
  2754.     fDimmed = state;
  2755.  
  2756.     if (mAGAObject != NULL)
  2757.         {
  2758.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  2759.  
  2760.         mAGAObject->SetEnable(!state, wantRedraw);
  2761.         }
  2762.     }
  2763.  
  2764. void AGAGroupBoxMA::Dim()
  2765.     {
  2766.     // Set the AGAObject's enable state, with immediate redraw.
  2767.  
  2768.     if (mAGAObject != NULL)
  2769.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  2770.     }
  2771.  
  2772. void AGAGroupBoxMA::SetLabel(const CStr255& theLabel, Boolean redraw)
  2773.     {
  2774.     // Change the current text in TCluster and in
  2775.     // the AGA object. Let TCluster use the redraw
  2776.     // to invalidate as usual.
  2777.  
  2778.     Inherited::SetLabel(theLabel, redraw);
  2779.  
  2780.     if (mAGAObject != NULL)
  2781.         {
  2782.         Str255    textString;
  2783.  
  2784.         AGA_PLstrcpy(textString, theLabel);
  2785.         mAGAObject->SetTitle(textString, AGAObject::kDontRedraw);
  2786.         }
  2787.     }
  2788.  
  2789. //
  2790. // AGASecondaryGroupBoxMA ----------------------------------------------------
  2791. //
  2792.  
  2793. #undef Inherited
  2794. #define Inherited AGAGroupBoxMA
  2795.  
  2796. MA_DEFINE_CLASS_M1(AGASecondaryGroupBoxMA, Inherited);
  2797.  
  2798. AGASecondaryGroupBoxMA::AGASecondaryGroupBoxMA()
  2799.     {
  2800.     mIsPrimaryType = false;
  2801.     }
  2802.  
  2803. AGASecondaryGroupBoxMA::~AGASecondaryGroupBoxMA()
  2804.     {
  2805.     }
  2806.  
  2807. void AGASecondaryGroupBoxMA::IAGASecondaryGroupBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, ResNumber itsRsrcID, short itsIndex)
  2808.     {
  2809.     this->IAGAGroupBoxMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex);
  2810.     }
  2811.  
  2812. //
  2813. // AGATabPanelMA ----------------------------------------------------
  2814. //
  2815.  
  2816. #undef Inherited
  2817. #define Inherited TControl
  2818.  
  2819. MA_DEFINE_CLASS_M1(AGATabPanelMA, Inherited);
  2820.  
  2821. AGATabPanelMA::AGATabPanelMA()
  2822.     {
  2823.     mAGAObject = NULL;
  2824.     mPanelContainerView = NULL;
  2825.     mActivePanelView = NULL;
  2826.     }
  2827.  
  2828. AGATabPanelMA::~AGATabPanelMA()
  2829.     {
  2830.     // Delete AGA object if we successfully allocated it.
  2831.     // We also need to make sure that all panel views not currently
  2832.     // installed get destructed.
  2833.  
  2834.     if (mAGAObject != NULL)
  2835.         {
  2836.         SInt32    numTabs;
  2837.  
  2838.         numTabs = mAGAObject->GetNumTabs();
  2839.         
  2840.         for (SInt32 tabIndex = 0; tabIndex < numTabs; tabIndex++)
  2841.             {
  2842.             if (tabIndex != mAGAObject->GetCurrentTab())
  2843.                 {
  2844.                 TView*    aPanelView = (TView*) mAGAObject->GetTabUserData(tabIndex);
  2845.                 (void) FreeIfObject(aPanelView);
  2846.                 }
  2847.             }
  2848.  
  2849.         delete mAGAObject;
  2850.         }
  2851.     }
  2852.  
  2853. void AGATabPanelMA::IAGATabPanelMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle)
  2854.     {
  2855.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  2856.  
  2857.     this->CreateAGAObject();
  2858.     
  2859.     // Create the container view that we'll load panels in and out of.
  2860.     
  2861.     this->CreateContainerView();
  2862.     }
  2863.  
  2864. void AGATabPanelMA::DoPostCreate(TDocument* itsDocument)
  2865.     {
  2866.     // Create and set up the AGAObject.
  2867.  
  2868.     Inherited::DoPostCreate(itsDocument);
  2869.     
  2870.     this->CreateAGAObject();
  2871.     
  2872.     // Create the container view that we'll load panels in and out of.
  2873.     
  2874.     this->CreateContainerView();
  2875.     }
  2876.  
  2877. void AGATabPanelMA::CreateAGAObject()
  2878.     {
  2879.     // Instantiate the particular AGAObject subclass.
  2880.  
  2881.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  2882.     CRect    bounds;
  2883.     
  2884.     this->ViewToQDRect(viewRect, bounds);
  2885.  
  2886.     FailNIL(mAGAObject = new AGATabPanel(bounds, 0, AGATextStyle(fTextStyle), fUserArea));
  2887.  
  2888.     if (fDimmed || ! fEnabled)
  2889.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  2890.  
  2891.     // Tabs have to erase when drawing, so make sure that
  2892.     // it doesn't assume we're on a gray background.
  2893.  
  2894.     this->Focus();
  2895.     InstallAGABackgroundColors(mAGAObject, kInstallOnlyIfCustom);
  2896.     }
  2897.  
  2898. void AGATabPanelMA::CreateContainerView()
  2899.     {
  2900.     if (mAGAObject->HasFrame())    // if no frame, we just run the tabs, not the panels
  2901.         {
  2902.         // Create a subview to contain the panels that we load and unload.
  2903.         // We locate it 3 pixels inset from our the frame content area.
  2904.         
  2905.         VCoordinate    tabHeight = mAGAObject->GetTabHeight();
  2906.         VPoint        viewLocation(3, 3 + tabHeight);
  2907.         VPoint        viewSize(fSize.h - 6, fSize.v - tabHeight - 6);
  2908.         
  2909.         mPanelContainerView = new TView;
  2910.         mPanelContainerView->IView(fDocument, this, viewLocation, viewSize,
  2911.                                     fSizeDeterminer[hSel], fSizeDeterminer[vSel]);
  2912.         }
  2913.     }
  2914.  
  2915. void AGATabPanelMA::Draw(const VRect& /*area*/)
  2916.     {
  2917.     // Let the AGAObject draw itself.
  2918.  
  2919.     if (mAGAObject != NULL)
  2920.         mAGAObject->DrawObject();
  2921.  
  2922.     // Set the background color so that any non-AGA subviews
  2923.     // that erase their background without assuming a color
  2924.     // will use our current tab panel color.
  2925.  
  2926.     if (this->IsEnabled())
  2927.         ::RGBBackColor(&gAGARamp[r1]);
  2928.     else
  2929.         ::RGBBackColor(&gAGARamp[r2]);
  2930.     }
  2931.  
  2932. void AGATabPanelMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  2933.     {
  2934.     // Let the MacApp and AGA objects update their locations.
  2935.     
  2936.     (void) this->Focus();
  2937.     CRect    frame;
  2938.     this->GetQDExtent(frame);
  2939.     ::InvalRect(frame);
  2940.     
  2941.     Inherited::SetFrame(newFrame, invalidate);
  2942.     
  2943.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  2944.     }
  2945.  
  2946. void AGATabPanelMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, CPoint /*hysteresis*/)
  2947.     {
  2948.     // Let the AGAObject track the mouse; if tracking succeeds
  2949.     // handle our event number.
  2950.  
  2951.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  2952.         this->HandleTabSwitch(mAGAObject->GetLastTabClicked());
  2953.     }
  2954.  
  2955. void AGATabPanelMA::DimState(Boolean state, Boolean redraw)
  2956.     {
  2957.     // Set the AGAObject's enable state.
  2958.  
  2959.     fDimmed = state;
  2960.  
  2961.     if (mAGAObject != NULL)
  2962.         {
  2963.         Boolean    wantRedraw = redraw && this->Focus() && this->IsVisible();
  2964.  
  2965.         mAGAObject->SetEnable(!state, wantRedraw);
  2966.         }
  2967.  
  2968.     this->SetSubviewsEnable(! state);
  2969.     }
  2970.  
  2971. void AGATabPanelMA::Dim()
  2972.     {
  2973.     // Set the AGAObject's enable state, with immediate redraw.
  2974.  
  2975.     if (mAGAObject != NULL)
  2976.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus() && this->IsVisible());
  2977.     }
  2978.  
  2979. void AGATabPanelMA::SetEnable(Boolean state)
  2980.     {
  2981.     Inherited::SetEnable(state);
  2982.  
  2983.     // Set the AGAObject's enable state, without redraw.
  2984.  
  2985.     if (mAGAObject != NULL)
  2986.         mAGAObject->SetEnable(state, AGAObject::kDontRedraw);
  2987.  
  2988.     this->SetSubviewsEnable(state);
  2989.     }
  2990.  
  2991. void AGATabPanelMA::SwitchPanels(SInt32 newTabIndex)
  2992.     {
  2993.     // Switch to the specified tab index.
  2994.     
  2995.     if (mAGAObject != NULL)
  2996.         mAGAObject->SetCurrentTab(newTabIndex, this->Focus());
  2997.  
  2998.     this->SwitchPanelIn(newTabIndex, this->SwitchPanelOut());
  2999.     }
  3000.  
  3001. void AGATabPanelMA::HandleTabSwitch(SInt32 newTabIndex)
  3002.     {
  3003.     // If it's OK to switch tabs (may need to validate current
  3004.     // panel before switching), do the switch.
  3005.  
  3006.     if (this->ValidatePanel(mAGAObject->GetCurrentTab()))
  3007.         {
  3008.         this->SwitchPanels(newTabIndex);
  3009.         this->HandleEvent(fEventNumber, this, NULL);
  3010.         }
  3011.     }
  3012.  
  3013. void AGATabPanelMA::AddPanel(SInt16 panelResourceID, StringPtr tabLabel)
  3014.     {
  3015.     // Create another tab and then install the specified View resource
  3016.     // onto that tab.
  3017.  
  3018.     if (mAGAObject != NULL)
  3019.         {
  3020.         Str255    actualTabLabel;
  3021.         SInt32    numTabs;
  3022.  
  3023.         if (tabLabel != NULL)
  3024.             AGA_PLstrcpy(actualTabLabel, tabLabel);
  3025.         else
  3026.             {
  3027.             Handle    viewHandle;
  3028.             SInt16    viewID;
  3029.             OSType    viewType;
  3030.             
  3031.             FailNIL(viewHandle = ::GetResource('View', panelResourceID));
  3032.             
  3033.             ::GetResInfo(viewHandle, &viewID, &viewType, actualTabLabel);
  3034.             
  3035.             // Don't release it -- we're about to cause it to be read anyway.
  3036.             }
  3037.  
  3038.         numTabs = mAGAObject->GetNumTabs();
  3039.         
  3040.         mAGAObject->SetNumTabs(numTabs + 1, AGATabPanel::kDontShrink);
  3041.         
  3042.         this->InstallPanel(numTabs, panelResourceID, actualTabLabel);
  3043.         }
  3044.     }
  3045.  
  3046. void AGATabPanelMA::InstallPanel(SInt32 tabIndex, SInt16 panelResourceID, StringPtr tabLabel)
  3047.     {
  3048.     // Install the specified View resource onto the specified existing tab.
  3049.  
  3050.     if (mAGAObject != NULL)
  3051.         {
  3052.         TView*    newPanelView;
  3053.         SInt32    numTabs;
  3054.  
  3055.         numTabs = mAGAObject->GetNumTabs();
  3056.         
  3057.         if (tabIndex < numTabs)
  3058.             {
  3059.             // Wrap the DoCreateViews with custom color values so that the
  3060.             // AGA objects in the panel hierarchy will get the right background
  3061.             // colors.
  3062.  
  3063.             TurnOnCustomAGABackgroundColors(&gAGARamp[r1], &gAGARamp[r2]);
  3064. //            FailNIL(newPanelView = gViewServer->DoCreateViews(fDocument, NULL, panelResourceID, gZeroVPt));
  3065.             FailNIL(newPanelView = gViewServer->DoCreateViews(fDocument, mPanelContainerView, panelResourceID, gZeroVPt));
  3066.             TurnOffCustomAGABackgroundColors();
  3067.  
  3068. newPanelView->Show(false, kRedraw);
  3069.  
  3070.             mAGAObject->SetTabUserData(tabIndex, newPanelView);
  3071.             
  3072.             if (tabLabel != NULL)
  3073.                 {
  3074.                 mAGAObject->SetTabLabel(tabIndex, tabLabel);
  3075.                 mAGAObject->CalculateTabWidths();
  3076.                 }
  3077.  
  3078.             // If this panel corresponds to the initial value, switch it in.
  3079.  
  3080.             if (mAGAObject->GetCurrentTab() == tabIndex)
  3081.                 this->SwitchPanels(tabIndex);
  3082.             }
  3083.         }
  3084.     }
  3085.  
  3086. TView* AGATabPanelMA::GetPanelView(SInt32 tabIndex)
  3087.     {
  3088.     // Return the TView* of the specified tab's panel view hierarchy.
  3089.  
  3090.     if (mAGAObject == NULL)
  3091.         return NULL;
  3092.     else
  3093.         return (TView*) mAGAObject->GetTabUserData(tabIndex);
  3094.     }
  3095.  
  3096. void AGATabPanelMA::SetSubviewsEnable(Boolean state)
  3097.     {
  3098.     // Do a recursive walk of our panel subviews, setting the
  3099.     // enable state of all of its subviews.
  3100.  
  3101.     if (mPanelContainerView != NULL)
  3102.         {
  3103.         this->DoSubviewsEnable(mPanelContainerView, state);
  3104.         
  3105.         mPanelContainerView->ForceRedraw();
  3106.         }
  3107.     }
  3108.  
  3109. void AGATabPanelMA::DoSubviewsEnable(TView* aSuperView, Boolean state)
  3110.     {
  3111.     // Do a recursive walk of our panel subviews, setting the
  3112.     // enable state of all of its subviews.
  3113.  
  3114.     CSubViewIterator    iter(aSuperView);
  3115.     
  3116.     for (TView* aSubView = iter.FirstSubView(); iter.More(); aSubView = iter.NextSubView())
  3117.         {
  3118.         aSubView->SetEnable(state);
  3119.  
  3120.         if (MA_MEMBER(aSubView, TControl))
  3121.             ((TControl*) aSubView)->DimState(! state, kDontRedraw);
  3122.         
  3123.         this->DoSubviewsEnable(aSubView, state);
  3124.         }
  3125.     }
  3126.  
  3127. Boolean AGATabPanelMA::ValidatePanel(SInt32 /*currentTabIndex*/)
  3128.     {
  3129.     // (Override for app-specific validation.)
  3130.     //
  3131.     // Return true if the current (specified) panel is valid and
  3132.     // it's OK to switch to a different panel. Return false otherwise
  3133.     // and the tab switch will not occur; it's OK to alert the user
  3134.     // of the invalid data before returning.
  3135.     //
  3136.  
  3137.     return true;
  3138.     }
  3139.  
  3140. Boolean AGATabPanelMA::SwitchPanelOut()
  3141.     {
  3142.     // Yank the current panel view hierarchy out of the container view.
  3143.     
  3144.     Boolean    panelContainedTarget = false;
  3145.  
  3146.     if (mActivePanelView != NULL)
  3147.         {
  3148.         TEventHandler*    currentTarget = gApplication->GetTarget();
  3149.         
  3150.         if (currentTarget != NULL)
  3151.             if (MA_MEMBER(currentTarget, TView))
  3152.                 if (mActivePanelView->ContainsSubView((TView*) currentTarget))
  3153.                     {
  3154.                     panelContainedTarget = true;
  3155.                     (void) currentTarget->ResignTarget();
  3156.                     }
  3157.  
  3158.         mActivePanelView->Show(false, kRedraw);
  3159.         //mPanelContainerView->RemoveSubView(mActivePanelView);
  3160.         mActivePanelView = NULL;
  3161.         }
  3162.     
  3163.     return panelContainedTarget;
  3164.     }
  3165.  
  3166. void AGATabPanelMA::SwitchPanelIn(SInt32 newTabIndex, Boolean targetInPanel)
  3167.     {
  3168.     // Switch the specified panel view hierarchy in buy placing it
  3169.     // inside the container view.
  3170.  
  3171.     if (mAGAObject != NULL)
  3172.         {
  3173.         TView*    newPanelView = (TView*) mAGAObject->GetTabUserData(newTabIndex);
  3174.         
  3175.         if (newPanelView != NULL)
  3176.             {
  3177.             mActivePanelView = newPanelView;
  3178.  
  3179.             //
  3180.             // Before redrawing, center the new panel inside the container.
  3181.             //
  3182. /*            
  3183.             VRect    containerFrame;
  3184.             VPoint    containerSize;
  3185.             VRect    panelFrame;
  3186.             VPoint    panelSize;
  3187.             VPoint    leftoverSize;
  3188.             
  3189.             mPanelContainerView->GetFrame(containerFrame);
  3190.             containerSize = containerFrame.GetSize();
  3191.             
  3192.             newPanelView->GetFrame(panelFrame);
  3193.             panelSize = panelFrame.GetSize();
  3194.             
  3195.             leftoverSize.h = containerSize.h - panelSize.h;
  3196.             leftoverSize.v = containerSize.v - panelSize.v;
  3197.             
  3198.             panelFrame.left = leftoverSize.h / 2;
  3199.             panelFrame.top = leftoverSize.v / 2;
  3200.             panelFrame.right = panelFrame.left + panelSize.h;
  3201.             panelFrame.bottom = panelFrame.top + panelSize.v;
  3202.             
  3203.             //
  3204.             // Install the panel as a subpane of the container,
  3205.             // then make it visible.
  3206.             //
  3207.  
  3208.             mPanelContainerView->AddSubView(newPanelView);
  3209.             
  3210.             newPanelView->SetFrame(panelFrame, kInvalidate);
  3211. */
  3212.             newPanelView->Show(true, kRedraw);
  3213.             
  3214.             if (targetInPanel)
  3215.                 {
  3216.                 TView*    wannabeTarget = newPanelView->FindTarget();
  3217.                 
  3218.                 if (wannabeTarget != NULL)
  3219.                     {
  3220.                     (void) wannabeTarget->BecomeTarget();
  3221.                     
  3222.                     if (MA_MEMBER(wannabeTarget, TEditText))
  3223.                         ((TEditText*) wannabeTarget)->SetTargetSelection(kRedraw);
  3224.                     }
  3225.                 }
  3226.             }
  3227.         }
  3228.     }
  3229.  
  3230. //
  3231. // AGASmallTabPanelMA ----------------------------------------------------
  3232. //
  3233.  
  3234. #undef Inherited
  3235. #define Inherited AGATabPanelMA
  3236.  
  3237. MA_DEFINE_CLASS_M1(AGASmallTabPanelMA, Inherited);
  3238.  
  3239. AGASmallTabPanelMA::AGASmallTabPanelMA()
  3240.     {
  3241.     }
  3242.  
  3243. AGASmallTabPanelMA::~AGASmallTabPanelMA()
  3244.     {
  3245.     }
  3246.  
  3247. void AGASmallTabPanelMA::IAGASmallTabPanelMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle)
  3248.     {
  3249.     this->IAGATabPanelMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  3250.     }
  3251.  
  3252. void AGASmallTabPanelMA::CreateAGAObject()
  3253.     {
  3254.     Inherited::CreateAGAObject();
  3255.     
  3256.     // Set the tabs to use the standard small appearance.
  3257.  
  3258.     mAGAObject->SetTabSize(AGATabPanel::kSmallTabs);
  3259.     mAGAObject->SetLabelsStyle(gAGAStdBoldSmallStyle);
  3260.     }
  3261.  
  3262.